コード例 #1
0
 def setUp(self):
     self.config = Config('config',
                          'esx',
                          server='localhost',
                          username='******',
                          password='******',
                          owner='owner',
                          env='env',
                          log_dir='',
                          log_file='')
     self.second_config = Config('second_config',
                                 'esx',
                                 server='localhost',
                                 username='******',
                                 password='******',
                                 owner='owner',
                                 env='env',
                                 log_dir='',
                                 log_file='')
     fake_virt = Mock()
     fake_virt.CONFIG_TYPE = 'esx'
     guests = [Guest('guest1', fake_virt, 1)]
     test_hypervisor = Hypervisor('test',
                                  guestIds=[Guest('guest1', fake_virt, 1)])
     assoc = {'hypervisors': [test_hypervisor]}
     self.fake_domain_list = DomainListReport(self.second_config, guests)
     self.fake_report = HostGuestAssociationReport(self.config, assoc)
コード例 #2
0
    def test_sending_guests(self, fromOptions, fromConfig, getLogger):
        options = Mock()
        options.oneshot = True
        options.interval = 0
        options.print_ = False
        fake_virt = Mock()
        fake_virt.CONFIG_TYPE = 'esx'
        test_hypervisor = Hypervisor('test',
                                     guestIds=[Guest('guest1', fake_virt, 1)])
        association = {'hypervisors': [test_hypervisor]}
        options.log_dir = ''
        options.log_file = ''
        getLogger.return_value = sentinel.logger
        fromConfig.return_value.config.name = 'test'
        virtwho = VirtWho(self.logger, options, config_dir="/nonexistant")
        config = Config("test",
                        "esx",
                        server="localhost",
                        username="******",
                        password="******",
                        owner="owner",
                        env="env")
        virtwho.configManager.addConfig(config)
        virtwho.queue = Queue()
        virtwho.queue.put(HostGuestAssociationReport(config, association))
        virtwho.run()

        fromConfig.assert_called_with(sentinel.logger, config)
        self.assertTrue(fromConfig.return_value.start.called)
        fromOptions.assert_called_with(self.logger, options)
コード例 #3
0
class TestManager(TestBase):
    """ Test of all available subscription managers. """
    guest1 = Guest('9c927368-e888-43b4-9cdb-91b10431b258',
                   xvirt,
                   Guest.STATE_RUNNING,
                   hypervisorType='QEMU')
    guest2 = Guest('d5ffceb5-f79d-41be-a4c1-204f836e144a',
                   xvirt,
                   Guest.STATE_SHUTOFF,
                   hypervisorType='QEMU')
    guestInfo = [guest1]

    mapping = {
        'hypervisors': [
            Hypervisor('9c927368-e888-43b4-9cdb-91b10431b258', []),
            Hypervisor('ad58b739-5288-4cbc-a984-bd771612d670',
                       [guest1, guest2])
        ]
    }
コード例 #4
0
 def _process_guest(self, guest):
     attributes = guest.get('attributes', {})
     self.CONFIG_TYPE = attributes.get('virtWhoType', 'fake')
     hypervisorType = attributes.get('hypervisorType', None)
     hypervisorVersion = attributes.get('hypervisorVersion', None)
     return Guest(guest['guestId'],
                  self,
                  guest['state'],
                  hypervisorType=hypervisorType,
                  hypervisorVersion=hypervisorVersion)
コード例 #5
0
 def listDomains(self):
     domains = []
     response = self.server.list(True)
     if response['status']['code'] != 0:
         self.logger.error("Unable to list virtual machines: %s" %
                           response['status']['message'])
     else:
         for vm in response['vmList']:
             domains.append(
                 Guest(vm['vmId'],
                       self,
                       VDSM_STATE_TO_GUEST_STATE.get(
                           vm['status'], Guest.STATE_UNKNOWN),
                       hypervisorType='qemu'))
     return domains
コード例 #6
0
    def test_getHostGuestMapping(self, mock_client):
        expected_hostname = 'Fake_hostname'
        expected_hypervisorId = 'Fake_uuid'
        expected_guestId = 'guest1UUID'
        expected_guest_state = Guest.STATE_RUNNING

        fake_parent = MagicMock()
        fake_parent.value = 'Fake_parent'

        fake_vm_id = MagicMock()
        fake_vm_id.value = 'guest1'

        fake_vm = MagicMock()
        fake_vm.ManagedObjectReference = [fake_vm_id]
        fake_vms = {
            'guest1': {
                'runtime.powerState': 'poweredOn',
                'config.uuid': expected_guestId
            }
        }
        self.esx.vms = fake_vms

        fake_host = {
            'hardware.systemInfo.uuid': expected_hypervisorId,
            'name': expected_hostname,
            'parent': fake_parent,
            'vm': fake_vm
        }
        fake_hosts = {'random-host-id': fake_host}
        self.esx.hosts = fake_hosts

        expected_result = Hypervisor(hypervisorId=expected_hypervisorId,
                                     name=expected_hostname,
                                     guestIds=[
                                         Guest(expected_guestId,
                                               self.esx,
                                               expected_guest_state,
                                               hypervisorType='vmware')
                                     ])
        result = self.esx.getHostGuestMapping()['hypervisors'][0]
        self.assertEqual(expected_result.toDict(), result.toDict())
コード例 #7
0
class TestSubscriptionManager(TestBase):
    guestList = [
        Guest('222', xvirt, Guest.STATE_RUNNING),
        Guest('111', xvirt, Guest.STATE_RUNNING),
        Guest('333', xvirt, Guest.STATE_RUNNING),
    ]
    mapping = {
        'hypervisors': [Hypervisor('123', guestList, name='TEST_HYPERVISOR')]
    }

    @classmethod
    @patch('rhsm.config.initConfig')
    @patch('rhsm.certificate.create_from_file')
    def setUpClass(cls, rhsmcert, rhsmconfig):
        super(TestSubscriptionManager, cls).setUpClass()
        config = Config('test', 'libvirt')
        cls.tempdir = tempfile.mkdtemp()
        with open(os.path.join(cls.tempdir, 'cert.pem'), 'w') as f:
            f.write("\n")

        rhsmcert.return_value.subject = {'CN': 123}
        rhsmconfig.return_value.get.side_effect = lambda group, key: {
            'consumerCertDir': cls.tempdir
        }.get(key, DEFAULT)
        cls.sm = SubscriptionManager(cls.logger, config)
        cls.sm.cert_uuid = 123

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree(cls.tempdir)

    @patch('rhsm.connection.UEPConnection')
    def test_sendVirtGuests(self, rhsmconnection):
        self.sm.sendVirtGuests(self.guestList)
        self.sm.connection.updateConsumer.assert_called_with(
            123, guest_uuids=[g.toDict() for g in self.guestList])

    @patch('rhsm.connection.UEPConnection')
    def test_hypervisorCheckIn(self, rhsmconnection):
        owner = "owner"
        env = "env"
        config = Config("test", "esx", owner=owner, env=env)
        # Ensure the data takes the proper for for the old API
        rhsmconnection.return_value.has_capability.return_value = False
        self.sm.hypervisorCheckIn(config, self.mapping)

        self.sm.connection.hypervisorCheckIn.assert_called_with(
            owner, env,
            dict((host.hypervisorId, [g.toDict() for g in host.guestIds])
                 for host in self.mapping['hypervisors']))

    @patch('rhsm.connection.UEPConnection')
    def test_hypervisorCheckInAsync(self, rhsmconnection):
        owner = 'owner'
        env = 'env'
        config = Config("test", "esx", owner=owner, env=env)
        # Ensure we try out the new API
        rhsmconnection.return_value.has_capability.return_value = True
        self.sm.hypervisorCheckIn(config, self.mapping)
        expected = {
            'hypervisors': [h.toDict() for h in self.mapping['hypervisors']]
        }
        self.sm.connection.hypervisorCheckIn.assert_called_with(
            owner, env, expected)
コード例 #8
0
class TestSatellite(TestBase):
    mapping = {
        'hypervisors': [
            Hypervisor('host-1', [
                Guest('guest1-1', xvirt, Guest.STATE_RUNNING),
                Guest('guest1-2', xvirt, Guest.STATE_SHUTOFF)
            ]),
            Hypervisor('host-2', [
                Guest('guest2-1', xvirt, Guest.STATE_RUNNING),
                Guest('guest2-2', xvirt, Guest.STATE_SHUTOFF),
                Guest('guest2-3', xvirt, Guest.STATE_RUNNING)
            ])
        ]
    }

    @classmethod
    def setUpClass(cls):
        super(TestSatellite, cls).setUpClass()
        cls.fake_server = FakeSatellite()
        cls.thread = threading.Thread(target=cls.fake_server.serve_forever)
        cls.thread.start()

    @classmethod
    def tearDownClass(cls):
        cls.fake_server.shutdown()

    def test_wrong_server(self):
        options = Options("wrong_server", "abc", "def")
        s = Satellite(self.logger, options)
        #self.assertRaises(SatelliteError, s.connect, "wrong_server", "abc", "def")
        options.env = "ENV"
        options.owner = "OWNER"

        s.hypervisorCheckIn(options, {'hypervisors': []}, "test")
        #self.assertRaises(SatelliteError, s.connect, "localhost", "abc", "def")

    def test_new_system(self):
        options = Options("http://localhost:%s" % TEST_PORT, "username",
                          "password")
        options.force_register = True
        s = Satellite(self.logger, options)

        # Register with wrong username
        #self.assertRaises(SatelliteError, s.connect, "http://localhost:8080", "wrong", "password", force_register=True)

        # Register with wrong password
        #self.assertRaises(SatelliteError, s.connect, "http://localhost:8080", "username", "wrong", force_register=True)

    def test_hypervisorCheckIn(self):
        options = Options("http://localhost:%s" % TEST_PORT, "username",
                          "password")
        options.force_register = True
        options.env = "ENV"
        options.owner = "OWNER"
        s = Satellite(self.logger, options)

        result = s.hypervisorCheckIn(options, self.mapping, "type")
        self.assertTrue("failedUpdate" in result)
        self.assertTrue("created" in result)
        self.assertTrue("updated" in result)

    def test_hypervisorCheckIn_preregistered(self):
        temp, filename = tempfile.mkstemp(suffix=TEST_SYSTEM_ID)
        self.addCleanup(os.unlink, filename)
        f = os.fdopen(temp, "wb")
        pickle.dump({'system_id': TEST_SYSTEM_ID}, f)
        f.close()

        options = Options("http://localhost:%s" % TEST_PORT, "username",
                          "password")
        options.env = "ENV"
        options.owner = "OWNER"
        s = Satellite(self.logger, options)

        s.HYPERVISOR_SYSTEMID_FILE = filename.replace(TEST_SYSTEM_ID, '%s')

        result = s.hypervisorCheckIn(options, self.mapping, "type")
        self.assertTrue("failedUpdate" in result)
        self.assertTrue("created" in result)
        self.assertTrue("updated" in result)