Ejemplo n.º 1
0
class CepkoResultTests(test_helpers.TestCase):
    def setUp(self):
        self.c = Cepko()
        raise test_helpers.SkipTest('This test is completely useless')

    def test_getitem(self):
        result = self.c.all()
        self.assertEqual("65b2fb23-8c03-4187-a3ba-8b7c919e889", result['uuid'])
        self.assertEqual([], result['requirements'])
        self.assertEqual("much server", result['tags'][0])
        self.assertEqual(1, result['smp'])

    def test_len(self):
        self.assertEqual(len(SERVER_CONTEXT), len(self.c.all()))

    def test_contains(self):
        result = self.c.all()
        self.assertTrue('uuid' in result)
        self.assertFalse('uid' in result)
        self.assertTrue('meta' in result)
        self.assertFalse('ssh_public_key' in result)

    def test_iter(self):
        self.assertEqual(sorted(SERVER_CONTEXT.keys()),
                         sorted([key for key in self.c.all()]))

    def test_with_list_as_result(self):
        result = self.c.get('tags')
        self.assertEqual('much server', result[0])
        self.assertTrue('very performance' in result)
        self.assertEqual(2, len(result))
Ejemplo n.º 2
0
class CepkoResultTests(test_helpers.TestCase):
    def setUp(self):
        self.c = Cepko()
        raise test_helpers.SkipTest('This test is completely useless')

    def test_getitem(self):
        result = self.c.all()
        self.assertEqual("65b2fb23-8c03-4187-a3ba-8b7c919e889", result['uuid'])
        self.assertEqual([], result['requirements'])
        self.assertEqual("much server", result['tags'][0])
        self.assertEqual(1, result['smp'])

    def test_len(self):
        self.assertEqual(len(SERVER_CONTEXT), len(self.c.all()))

    def test_contains(self):
        result = self.c.all()
        self.assertTrue('uuid' in result)
        self.assertFalse('uid' in result)
        self.assertTrue('meta' in result)
        self.assertFalse('ssh_public_key' in result)

    def test_iter(self):
        self.assertEqual(sorted(SERVER_CONTEXT.keys()),
                         sorted([key for key in self.c.all()]))

    def test_with_list_as_result(self):
        result = self.c.get('tags')
        self.assertEqual('much server', result[0])
        self.assertTrue('very performance' in result)
        self.assertEqual(2, len(result))
Ejemplo n.º 3
0
class CepkoResultTests(test_helpers.TestCase):
    def setUp(self):
        self.c = Cepko()
        raise test_helpers.SkipTest("This test is completely useless")

    def test_getitem(self):
        result = self.c.all()
        self.assertEqual("65b2fb23-8c03-4187-a3ba-8b7c919e889", result["uuid"])
        self.assertEqual([], result["requirements"])
        self.assertEqual("much server", result["tags"][0])
        self.assertEqual(1, result["smp"])

    def test_len(self):
        self.assertEqual(len(SERVER_CONTEXT), len(self.c.all()))

    def test_contains(self):
        result = self.c.all()
        self.assertTrue("uuid" in result)
        self.assertFalse("uid" in result)
        self.assertTrue("meta" in result)
        self.assertFalse("ssh_public_key" in result)

    def test_iter(self):
        self.assertEqual(
            sorted(SERVER_CONTEXT.keys()),
            sorted([key for key in self.c.all()]),
        )

    def test_with_list_as_result(self):
        result = self.c.get("tags")
        self.assertEqual("much server", result[0])
        self.assertTrue("very performance" in result)
        self.assertEqual(2, len(result))
class DataSourceCloudSigma(sources.DataSource):
    """
    Uses cepko in order to gather the server context from the VM.

    For more information about CloudSigma's Server Context:
    http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html
    """
    def __init__(self, sys_cfg, distro, paths):
        self.dsmode = 'local'
        self.cepko = Cepko()
        self.ssh_public_key = ''
        sources.DataSource.__init__(self, sys_cfg, distro, paths)

    def get_data(self):
        """
        Metadata is the whole server context and /meta/cloud-config is used
        as userdata.
        """
        dsmode = None
        try:
            server_context = self.cepko.all().result
            server_meta = server_context['meta']
        except:
            # TODO: check for explicit "config on", and then warn
            # but since no explicit config is available now, just debug.
            LOG.debug("CloudSigma: Unable to read from serial port")
            return False

        dsmode = server_meta.get('cloudinit-dsmode', self.dsmode)
        if dsmode not in VALID_DSMODES:
            LOG.warn("Invalid dsmode %s, assuming default of 'net'", dsmode)
            dsmode = 'net'
        if dsmode == "disabled" or dsmode != self.dsmode:
            return False

        base64_fields = server_meta.get('base64_fields', '').split(',')
        self.userdata_raw = server_meta.get('cloudinit-user-data', "")
        if 'cloudinit-user-data' in base64_fields:
            self.userdata_raw = b64decode(self.userdata_raw)

        self.metadata = server_context
        self.ssh_public_key = server_meta['ssh_public_key']

        return True

    def get_hostname(self, fqdn=False, resolve_ip=False):
        """
        Cleans up and uses the server's name if the latter is set. Otherwise
        the first part from uuid is being used.
        """
        if re.match(r'^[A-Za-z0-9 -_\.]+$', self.metadata['name']):
            return self.metadata['name'][:61]
        else:
            return self.metadata['uuid'].split('-')[0]

    def get_public_ssh_keys(self):
        return [self.ssh_public_key]

    def get_instance_id(self):
        return self.metadata['uuid']
Ejemplo n.º 5
0
class DataSourceCloudSigma(sources.DataSource):
    """
    Uses cepko in order to gather the server context from the VM.

    For more information about CloudSigma's Server Context:
    http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html
    """
    def __init__(self, sys_cfg, distro, paths):
        self.dsmode = 'local'
        self.cepko = Cepko()
        self.ssh_public_key = ''
        sources.DataSource.__init__(self, sys_cfg, distro, paths)

    def get_data(self):
        """
        Metadata is the whole server context and /meta/cloud-config is used
        as userdata.
        """
        dsmode = None
        try:
            server_context = self.cepko.all().result
            server_meta = server_context['meta']
        except:
            util.logexc(LOG, "Failed reading from the serial port")
            return False

        dsmode = server_meta.get('cloudinit-dsmode', self.dsmode)
        if dsmode not in VALID_DSMODES:
            LOG.warn("Invalid dsmode %s, assuming default of 'net'", dsmode)
            dsmode = 'net'
        if dsmode == "disabled" or dsmode != self.dsmode:
            return False

        base64_fields = server_meta.get('base64_fields', '').split(',')
        self.userdata_raw = server_meta.get('cloudinit-user-data', "")
        if 'cloudinit-user-data' in base64_fields:
            self.userdata_raw = b64decode(self.userdata_raw)

        self.metadata = server_context
        self.ssh_public_key = server_meta['ssh_public_key']

        return True

    def get_hostname(self, fqdn=False, resolve_ip=False):
        """
        Cleans up and uses the server's name if the latter is set. Otherwise
        the first part from uuid is being used.
        """
        if re.match(r'^[A-Za-z0-9 -_\.]+$', self.metadata['name']):
            return self.metadata['name'][:61]
        else:
            return self.metadata['uuid'].split('-')[0]

    def get_public_ssh_keys(self):
        return [self.ssh_public_key]

    def get_instance_id(self):
        return self.metadata['uuid']
Ejemplo n.º 6
0
class CepkoResultTests(MockerTestCase):
    def setUp(self):
        self.mocked = self.mocker.replace("cloudinit.cs_utils.Cepko",
                                          spec=CepkoMock,
                                          count=False,
                                          passthrough=False)
        self.mocked()
        self.mocker.result(CepkoMock())
        self.mocker.replay()
        self.c = Cepko()

    def test_getitem(self):
        result = self.c.all()
        self.assertEqual("65b2fb23-8c03-4187-a3ba-8b7c919e889", result['uuid'])
        self.assertEqual([], result['requirements'])
        self.assertEqual("much server", result['tags'][0])
        self.assertEqual(1, result['smp'])

    def test_len(self):
        self.assertEqual(len(SERVER_CONTEXT), len(self.c.all()))

    def test_contains(self):
        result = self.c.all()
        self.assertTrue('uuid' in result)
        self.assertFalse('uid' in result)
        self.assertTrue('meta' in result)
        self.assertFalse('ssh_public_key' in result)

    def test_iter(self):
        self.assertEqual(sorted(SERVER_CONTEXT.keys()),
                         sorted([key for key in self.c.all()]))

    def test_with_list_as_result(self):
        result = self.c.get('tags')
        self.assertEqual('much server', result[0])
        self.assertTrue('very performance' in result)
        self.assertEqual(2, len(result))
Ejemplo n.º 7
0
class CepkoResultTests(MockerTestCase):
    def setUp(self):
        self.mocked = self.mocker.replace("cloudinit.cs_utils.Cepko",
                            spec=CepkoMock,
                            count=False,
                            passthrough=False)
        self.mocked()
        self.mocker.result(CepkoMock())
        self.mocker.replay()
        self.c = Cepko()

    def test_getitem(self):
        result = self.c.all()
        self.assertEqual("65b2fb23-8c03-4187-a3ba-8b7c919e889", result['uuid'])
        self.assertEqual([], result['requirements'])
        self.assertEqual("much server", result['tags'][0])
        self.assertEqual(1, result['smp'])

    def test_len(self):
        self.assertEqual(len(SERVER_CONTEXT), len(self.c.all()))

    def test_contains(self):
        result = self.c.all()
        self.assertTrue('uuid' in result)
        self.assertFalse('uid' in result)
        self.assertTrue('meta' in result)
        self.assertFalse('ssh_public_key' in result)

    def test_iter(self):
        self.assertEqual(sorted(SERVER_CONTEXT.keys()),
                         sorted([key for key in self.c.all()]))

    def test_with_list_as_result(self):
        result = self.c.get('tags')
        self.assertEqual('much server', result[0])
        self.assertTrue('very performance' in result)
        self.assertEqual(2, len(result))
Ejemplo n.º 8
0
class DataSourceCloudSigma(sources.DataSource):
    """
    Uses cepko in order to gather the server context from the VM.

    For more information about CloudSigma's Server Context:
    http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html
    """
    def __init__(self, sys_cfg, distro, paths):
        self.dsmode = 'local'
        self.cepko = Cepko()
        self.ssh_public_key = ''
        sources.DataSource.__init__(self, sys_cfg, distro, paths)

    def is_running_in_cloudsigma(self):
        """
        Uses dmidecode to detect if this instance of cloud-init is running
        in the CloudSigma's infrastructure.
        """
        uname_arch = os.uname()[4]
        if uname_arch.startswith("arm") or uname_arch == "aarch64":
            # Disabling because dmidecode in CMD_DMI_SYSTEM crashes kvm process
            LOG.debug("Disabling CloudSigma datasource on arm (LP: #1243287)")
            return False

        dmidecode_path = util.which('dmidecode')
        if not dmidecode_path:
            return False

        LOG.debug("Determining hypervisor product name via dmidecode")
        try:
            cmd = [dmidecode_path, "--string", "system-product-name"]
            system_product_name, _ = util.subp(cmd)
            return 'cloudsigma' in system_product_name.lower()
        except:
            LOG.warn("Failed to get hypervisor product name via dmidecode")

        return False

    def get_data(self):
        """
        Metadata is the whole server context and /meta/cloud-config is used
        as userdata.
        """
        dsmode = None
        if not self.is_running_in_cloudsigma():
            return False

        try:
            server_context = self.cepko.all().result
            server_meta = server_context['meta']
        except:
            # TODO: check for explicit "config on", and then warn
            # but since no explicit config is available now, just debug.
            LOG.debug("CloudSigma: Unable to read from serial port")
            return False

        dsmode = server_meta.get('cloudinit-dsmode', self.dsmode)
        if dsmode not in VALID_DSMODES:
            LOG.warn("Invalid dsmode %s, assuming default of 'net'", dsmode)
            dsmode = 'net'
        if dsmode == "disabled" or dsmode != self.dsmode:
            return False

        base64_fields = server_meta.get('base64_fields', '').split(',')
        self.userdata_raw = server_meta.get('cloudinit-user-data', "")
        if 'cloudinit-user-data' in base64_fields:
            self.userdata_raw = b64decode(self.userdata_raw)
        if 'cloudinit' in server_context.get('vendor_data', {}):
            self.vendordata_raw = server_context["vendor_data"]["cloudinit"]

        self.metadata = server_context
        self.ssh_public_key = server_meta['ssh_public_key']

        return True

    def get_hostname(self, fqdn=False, resolve_ip=False):
        """
        Cleans up and uses the server's name if the latter is set. Otherwise
        the first part from uuid is being used.
        """
        if re.match(r'^[A-Za-z0-9 -_\.]+$', self.metadata['name']):
            return self.metadata['name'][:61]
        else:
            return self.metadata['uuid'].split('-')[0]

    def get_public_ssh_keys(self):
        return [self.ssh_public_key]

    def get_instance_id(self):
        return self.metadata['uuid']
Ejemplo n.º 9
0
class DataSourceCloudSigma(sources.DataSource):
    """
    Uses cepko in order to gather the server context from the VM.

    For more information about CloudSigma's Server Context:
    http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html
    """
    def __init__(self, sys_cfg, distro, paths):
        self.cepko = Cepko()
        self.ssh_public_key = ''
        sources.DataSource.__init__(self, sys_cfg, distro, paths)

    def is_running_in_cloudsigma(self):
        """
        Uses dmi data to detect if this instance of cloud-init is running
        in the CloudSigma's infrastructure.
        """

        LOG.debug("determining hypervisor product name via dmi data")
        sys_product_name = util.read_dmi_data("system-product-name")
        if not sys_product_name:
            LOG.debug("system-product-name not available in dmi data")
            return False
        else:
            LOG.debug("detected hypervisor as %s", sys_product_name)
            return 'cloudsigma' in sys_product_name.lower()

        LOG.warn("failed to query dmi data for system product name")
        return False

    def get_data(self):
        """
        Metadata is the whole server context and /meta/cloud-config is used
        as userdata.
        """
        dsmode = None
        if not self.is_running_in_cloudsigma():
            return False

        try:
            server_context = self.cepko.all().result
            server_meta = server_context['meta']
        except Exception:
            # TODO: check for explicit "config on", and then warn
            # but since no explicit config is available now, just debug.
            LOG.debug("CloudSigma: Unable to read from serial port")
            return False

        self.dsmode = self._determine_dsmode(
            [server_meta.get('cloudinit-dsmode')])
        if dsmode == sources.DSMODE_DISABLED:
            return False

        base64_fields = server_meta.get('base64_fields', '').split(',')
        self.userdata_raw = server_meta.get('cloudinit-user-data', "")
        if 'cloudinit-user-data' in base64_fields:
            self.userdata_raw = b64decode(self.userdata_raw)
        if 'cloudinit' in server_context.get('vendor_data', {}):
            self.vendordata_raw = server_context["vendor_data"]["cloudinit"]

        self.metadata = server_context
        self.ssh_public_key = server_meta['ssh_public_key']

        return True

    def get_hostname(self, fqdn=False, resolve_ip=False):
        """
        Cleans up and uses the server's name if the latter is set. Otherwise
        the first part from uuid is being used.
        """
        if re.match(r'^[A-Za-z0-9 -_\.]+$', self.metadata['name']):
            return self.metadata['name'][:61]
        else:
            return self.metadata['uuid'].split('-')[0]

    def get_public_ssh_keys(self):
        return [self.ssh_public_key]

    def get_instance_id(self):
        return self.metadata['uuid']
class DataSourceCloudSigma(sources.DataSource):
    """
    Uses cepko in order to gather the server context from the VM.

    For more information about CloudSigma's Server Context:
    http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html
    """
    def __init__(self, sys_cfg, distro, paths):
        self.cepko = Cepko()
        self.ssh_public_key = ''
        sources.DataSource.__init__(self, sys_cfg, distro, paths)

    def is_running_in_cloudsigma(self):
        """
        Uses dmi data to detect if this instance of cloud-init is running
        in the CloudSigma's infrastructure.
        """
        uname_arch = os.uname()[4]
        if uname_arch.startswith("arm") or uname_arch == "aarch64":
            # Disabling because dmi data on ARM processors
            LOG.debug("Disabling CloudSigma datasource on arm (LP: #1243287)")
            return False

        LOG.debug("determining hypervisor product name via dmi data")
        sys_product_name = util.read_dmi_data("system-product-name")
        if not sys_product_name:
            LOG.debug("system-product-name not available in dmi data")
            return False
        else:
            LOG.debug("detected hypervisor as %s", sys_product_name)
            return 'cloudsigma' in sys_product_name.lower()

        LOG.warn("failed to query dmi data for system product name")
        return False

    def get_data(self):
        """
        Metadata is the whole server context and /meta/cloud-config is used
        as userdata.
        """
        dsmode = None
        if not self.is_running_in_cloudsigma():
            return False

        try:
            server_context = self.cepko.all().result
            server_meta = server_context['meta']
        except Exception:
            # TODO: check for explicit "config on", and then warn
            # but since no explicit config is available now, just debug.
            LOG.debug("CloudSigma: Unable to read from serial port")
            return False

        self.dsmode = self._determine_dsmode(
            [server_meta.get('cloudinit-dsmode')])
        if dsmode == sources.DSMODE_DISABLED:
            return False

        base64_fields = server_meta.get('base64_fields', '').split(',')
        self.userdata_raw = server_meta.get('cloudinit-user-data', "")
        if 'cloudinit-user-data' in base64_fields:
            self.userdata_raw = b64decode(self.userdata_raw)
        if 'cloudinit' in server_context.get('vendor_data', {}):
            self.vendordata_raw = server_context["vendor_data"]["cloudinit"]

        self.metadata = server_context
        self.ssh_public_key = server_meta['ssh_public_key']

        return True

    def get_hostname(self, fqdn=False, resolve_ip=False):
        """
        Cleans up and uses the server's name if the latter is set. Otherwise
        the first part from uuid is being used.
        """
        if re.match(r'^[A-Za-z0-9 -_\.]+$', self.metadata['name']):
            return self.metadata['name'][:61]
        else:
            return self.metadata['uuid'].split('-')[0]

    def get_public_ssh_keys(self):
        return [self.ssh_public_key]

    def get_instance_id(self):
        return self.metadata['uuid']
class DataSourceCloudSigma(sources.DataSource):
    """
    Uses cepko in order to gather the server context from the VM.

    For more information about CloudSigma's Server Context:
    http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html
    """

    def __init__(self, sys_cfg, distro, paths):
        self.dsmode = "local"
        self.cepko = Cepko()
        self.ssh_public_key = ""
        sources.DataSource.__init__(self, sys_cfg, distro, paths)

    def get_data(self):
        """
        Metadata is the whole server context and /meta/cloud-config is used
        as userdata.
        """
        dsmode = None
        try:
            server_context = self.cepko.all().result
            server_meta = server_context["meta"]
        except:
            # TODO: check for explicit "config on", and then warn
            # but since no explicit config is available now, just debug.
            LOG.debug("CloudSigma: Unable to read from serial port")
            return False

        dsmode = server_meta.get("cloudinit-dsmode", self.dsmode)
        if dsmode not in VALID_DSMODES:
            LOG.warn("Invalid dsmode %s, assuming default of 'net'", dsmode)
            dsmode = "net"
        if dsmode == "disabled" or dsmode != self.dsmode:
            return False

        base64_fields = server_meta.get("base64_fields", "").split(",")
        self.userdata_raw = server_meta.get("cloudinit-user-data", "")
        if "cloudinit-user-data" in base64_fields:
            self.userdata_raw = b64decode(self.userdata_raw)

        self.metadata = server_context
        self.ssh_public_key = server_meta["ssh_public_key"]

        return True

    def get_hostname(self, fqdn=False, resolve_ip=False):
        """
        Cleans up and uses the server's name if the latter is set. Otherwise
        the first part from uuid is being used.
        """
        if re.match(r"^[A-Za-z0-9 -_\.]+$", self.metadata["name"]):
            return self.metadata["name"][:61]
        else:
            return self.metadata["uuid"].split("-")[0]

    def get_public_ssh_keys(self):
        return [self.ssh_public_key]

    def get_instance_id(self):
        return self.metadata["uuid"]