Ejemplo n.º 1
0
 def test_get_vm_info_with_openstack_sys_vendor(self):
     """
     L{get_vm_info} should return "kvm" when we detect the sys_vendor is
     Openstack.
     """
     self.make_sys_vendor("OpenStack Foundation")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 2
0
 def test_get_vm_info_with_virtualbox_sys_vendor(self):
     """
     L{get_vm_info} should return "virtualbox" when we detect the sys_vendor
     is innotek. GmbH.
     """
     self.make_sys_vendor("innotek GmbH")
     self.assertEqual(b"virtualbox", get_vm_info(root_path=self.root_path))
Ejemplo n.º 3
0
 def test_get_vm_info_with_ec2_sys_vendor(self):
     """
     get_vm_info should return "kvm" when sys_vendor is "Amazon EC2",
     which is the case for C5 instances which are based on KVM.
     """
     self.make_sys_vendor("Amazon EC2")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 4
0
 def test_get_vm_info_with_bochs_sys_vendor(self):
     """
     L{get_vm_info} should return "kvm" when we detect the sys_vendor is
     Bochs.
     """
     self.make_dmi_info("sys_vendor", "Bochs")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 5
0
 def test_get_vm_info_with_vmware_sys_vendor(self):
     """
     L{get_vm_info} should return "vmware" when we detect the sys_vendor is
     VMware Inc.
     """
     self.make_sys_vendor("VMware, Inc.")
     self.assertEqual(b"vmware", get_vm_info(root_path=self.root_path))
Ejemplo n.º 6
0
 def test_get_vm_info_with_kvm_bios_vendor(self):
     """
     get_vm_info should return "kvm" when bios_vendor maps to kvm.
     """
     # DigitalOcean is known to set the bios_vendor on their instances.
     self.make_dmi_info("bios_vendor", "DigitalOcean")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 7
0
 def test_get_vm_info_with_other_vendor(self):
     """
     L{get_vm_info} should return an empty string when the sys_vendor is
     unknown.
     """
     self.make_sys_vendor("Some other vendor")
     self.assertEqual(b"", get_vm_info(root_path=self.root_path))
Ejemplo n.º 8
0
 def test_get_vm_info_with_qemu_sys_vendor(self):
     """
     L{get_vm_info} should return "kvm" when we detect the sys_vendor is
     QEMU.
     """
     self.make_sys_vendor("QEMU")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 9
0
    def test_get_vm_info_is_openvz_when_proc_vz_exists(self):
        """
        L{get_vm_info} should return 'openvz' when /proc/vz exists.
        """
        proc_vz_path = os.path.join(self.proc_path, "vz")
        self.makeFile(path=proc_vz_path, content="foo")

        self.assertEqual(b"openvz", get_vm_info(root_path=self.root_path))
Ejemplo n.º 10
0
 def test_get_vm_info_with_bochs_chassis_vendor(self):
     """
     get_vm_info should return "kvm" when chassis_vendor is "Bochs".
     """
     # DigitalOcean, AWS and Cloudstack are known to customize sys_vendor
     # and/or bios_vendor.
     self.make_dmi_info("sys_vendor", "Apache Software Foundation")
     self.make_dmi_info("chassis_vendor", "Bochs")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 11
0
    def test_get_vm_info_is_empty_without_xen_devices(self):
        """
        L{get_vm_info} returns an empty string if the /sys/bus/xen/devices
        directory exists but doesn't contain any file.
        """
        devices_xen_path = os.path.join(self.sys_path, "bus/xen/devices")
        self.makeDir(path=devices_xen_path)

        self.assertEqual(b"", get_vm_info(root_path=self.root_path))
Ejemplo n.º 12
0
    def test_get_vm_info_is_xen_when_sys_bus_xen_is_non_empty(self):
        """
        L{get_vm_info} should return 'xen' when /sys/bus/xen exists and has
        devices.
        """
        devices_xen_path = os.path.join(self.sys_path, "bus/xen/devices")
        self.makeDir(path=devices_xen_path)
        foo_devices_path = os.path.join(devices_xen_path, "foo")
        self.makeFile(path=foo_devices_path, content="bar")

        self.assertEqual(b"xen", get_vm_info(root_path=self.root_path))
Ejemplo n.º 13
0
 def test_get_vm_info_with_kvm_on_other_architecture(self):
     """
     L{get_vm_info} returns 'kvm', if no sys_vendor is available but the
     model in /proc/cpuinfo contains 'emulated by qemu'.
     """
     cpuinfo_path = os.path.join(self.proc_path, "cpuinfo")
     cpuinfo = ("platform	: Some Machine\n"
                "model	: Some CPU (emulated by qemu)\n"
                "machine	: Some Machine (emulated by qemu)\n")
     self.makeFile(path=cpuinfo_path, content=cpuinfo)
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 14
0
 def test_get_vm_info_with_microsoft_sys_vendor(self):
     """
     L{get_vm_info} returns "hyperv" if the sys_vendor is Microsoft.
     """
     self.make_sys_vendor("Microsoft Corporation")
     self.assertEqual(b"hyperv", get_vm_info(root_path=self.root_path))
Ejemplo n.º 15
0
 def test_get_vm_info_with_rhev(self):
     """get_vm_info returns 'kvm' if running under RHEV Hypervisor."""
     self.make_dmi_info("product_name", "RHEV Hypervisor")
     self.make_dmi_info("sys_vendor", "Red Hat")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 16
0
 def test_get_vm_info_empty_when_no_virtualization_is_found(self):
     """
     L{get_vm_info} should be empty when there's no virtualisation.
     """
     self.assertEqual(b"", get_vm_info(root_path=self.root_path))
Ejemplo n.º 17
0
 def test_get_vm_info_with_kvm_product(self):
     """get_vm_info returns 'kvm', if product_name is 'KVM'."""
     self.make_dmi_info("product_name", "KVM")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 18
0
 def test_get_vm_info_with_digitalocean_sys_vendor(self):
     """
     get_vm_info should return "kvm" when sys_vendor is "DigitalOcean".
     """
     self.make_sys_vendor("DigitalOcean")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 19
0
 def test_get_vm_info_with_google_sys_vendor(self):
     """
     L{get_vm_info} returns "gce" if the sys_vendor is Google.
     """
     self.make_sys_vendor("Google")
     self.assertEqual(b"gce", get_vm_info(root_path=self.root_path))
Ejemplo n.º 20
0
 def test_get_vm_info_matches_insensitive(self):
     """
     L{get_vm_info} matches the vendor string in a case-insentive way.
     """
     self.make_sys_vendor("openstack foundation")
     self.assertEqual(b"kvm", get_vm_info(root_path=self.root_path))
Ejemplo n.º 21
0
    def _handle_pre_exchange(self):
        """
        An exchange is about to happen.  If we don't have a secure id already
        set, and we have the needed information available, queue a registration
        message with the server.
        """
        # The point of storing this flag is that if we should *not* register
        # now, and then after the exchange we *should*, we schedule an urgent
        # exchange again.  Without this flag we would just spin trying to
        # connect to the server when something is clearly preventing the
        # registration.
        self._should_register = self.should_register()
        if not self._should_register:
            return

        # These are just to shorten the code.
        identity = self._identity
        account_name = identity.account_name

        if not account_name:
            self._reactor.fire("registration-failed", reason="unknown-account")
            return

        tags = identity.tags
        group = identity.access_group
        registration_key = identity.registration_key

        self._message_store.delete_all_messages()

        if not is_valid_tag_list(tags):
            tags = None
            logging.error("Invalid tags provided for registration.")

        message = {
            "type": "register",
            "hostname": get_fqdn(),
            "account_name": account_name,
            "computer_title": identity.computer_title,
            "registration_password": identity.registration_key,
            "tags": tags,
            "container-info": get_container_info(),
            "vm-info": get_vm_info()
        }

        if self._clone_secure_id:
            # We use the secure id here because the registration is encrypted
            # and the insecure id has been already exposed to unencrypted
            # http from the ping server. In addition it's more straightforward
            # to get the computer from the server through it than the insecure
            message["clone_secure_id"] = self._clone_secure_id

        if group:
            message["access_group"] = group

        server_api = self._message_store.get_server_api()
        # If we have juju data to send and if the server is recent enough to
        # know how to handle juju data, then we include it in the registration
        # message. We want to trigger the 3.3 server handler because client
        # version 14.01 has a different format for the juju-info field,
        # so this makes sure that the correct schema is used by the server
        # when validating our message.
        if self._juju_data and is_version_higher(server_api, b"3.3"):
            message["juju-info"] = {
                "environment-uuid": self._juju_data["environment-uuid"],
                "api-addresses": self._juju_data["api-addresses"],
                "machine-id": self._juju_data["machine-id"]
            }

        # The computer is a normal computer, possibly a container.
        with_word = "with" if bool(registration_key) else "without"
        with_tags = "and tags %s " % tags if tags else ""
        with_group = "in access group '%s' " % group if group else ""

        logging.info(u"Queueing message to register with account %r %s%s"
                     "%s a password." %
                     (account_name, with_group, with_tags, with_word))
        self._exchange.send(message)