diff --git a/avocado/utils/cloudinit.py b/avocado/utils/cloudinit.py index 253e5afabe..d3d168bf78 100644 --- a/avocado/utils/cloudinit.py +++ b/avocado/utils/cloudinit.py @@ -17,6 +17,8 @@ This module can be easily used with :mod:`avocado.utils.vmimage`, to configure operating system images via the cloudinit tooling. + +:see: http://cloudinit.readthedocs.io. """ from http.server import HTTPServer @@ -27,6 +29,7 @@ #: The meta-data file template +#: #: Positional template variables are: instance-id, hostname METADATA_TEMPLATE = """instance-id: {0} hostname: {1} @@ -36,6 +39,7 @@ USERDATA_HEADER = "#cloud-config" #: A username configuration as per cloudinit/config/cc_set_passwords.py +#: #: Positional template variables : username USERNAME_TEMPLATE = """ ssh_pwauth: True @@ -46,7 +50,8 @@ """ #: A username configuration as per cloudinit/config/cc_set_passwords.py -#: Positional template variables : password +#: +#: Positional template variables are: password PASSWORD_TEMPLATE = """ password: {0} chpasswd: @@ -54,12 +59,15 @@ """ #: An authorized key configuration for the default user +#: +#: Positional template variables are: ssh_authorized_keys AUTHORIZED_KEY_TEMPLATE = """ ssh_authorized_keys: - {0} """ #: A phone home configuration that will post just the instance id +#: #: Positional template variables are: address, port PHONE_HOME_TEMPLATE = """ phone_home: @@ -122,8 +130,13 @@ def iso(output_path, instance_id, username=None, password=None, class PhoneHomeServerHandler(BaseHTTPRequestHandler): + """Handles HTTP requests to the phone home server.""" def do_POST(self): + """Handles an HTTP POST request. + + Respond with status 200 if the instance phoned back. + """ path = self.path[1:] if path[-1] == '/': path = path[:-1] @@ -132,12 +145,28 @@ def do_POST(self): self.send_response(200) def log_message(self, format_, *args): # pylint: disable=W0221 - pass + """Logs an arbitrary message. + + :note: It currently disables any message logging. + """ class PhoneHomeServer(HTTPServer): + """Implements the phone home HTTP server. + + Wait the phone home from a given instance. + """ def __init__(self, address, instance_id): + """Initialize the server. + + :param address: a hostname or IP address and port, in the same format + given to socket and other servers + :type address: tuple + :param instance_id: the identification for the instance that should be + calling back, and the condition for the wait to end + :type instance_id: str + """ HTTPServer.__init__(self, address, PhoneHomeServerHandler) self.instance_id = instance_id self.instance_phoned_back = False