Beispiel #1
0
    def _create_destinations(self):
        """Populate self.destinations with a list of  list with them

            @param reset: Whether to kill existing destinations or not, defaults
            to false
            @type: bool
        """
        dests = []
        for info in self.dest_to_source_mapper.dests:
            # Dests should already include all destinations we want created
            # at this time. This method will make no assumptions of creating
            # defaults of any kind.
            source_keys = self.dest_to_source_mapper.dest_to_sources_map[info]
            info.name = "destination_%s" % hash(info)
            logger = log.getLogger(name=info.name)
            manager = Manager.fromInfo(logger, self.options, info)
            dest_class = info_to_destination_class[type(info)]
            dest = dest_class(config=info, logger=logger,
                              source_keys=source_keys,
                              options=self.options,
                              source=self.datastore, dest=manager,
                              terminate_event=self.terminate_event,
                              interval=self.options[VW_GLOBAL]['interval'],
                              oneshot=self.options[VW_GLOBAL]['oneshot'])
            dests.append(dest)
        return dests
Beispiel #2
0
    def test_satellite_config_file(self):
        # Username and password are required for a valid sat5 destination
        with open(os.path.join(self.config_dir, "test.conf"), "w") as f:
            f.write("""
[test]
type=libvirt
sat_server=sat.example.com
sat_username=sat_username
sat_password=sat_password
""")
        conf = parse_file(os.path.join(self.config_dir, "test.conf"))
        effective_config = EffectiveConfig()
        conf_values = conf.pop("test")
        effective_config["test"] = ConfigSection.from_dict(
            conf_values,
            "test",
            effective_config
        )
        config_manager = DestinationToSourceMapper(effective_config)
        self.assertEqual(len(config_manager.configs), 1)
        # There should only be one destination detected
        self.assertEqual(len(config_manager.dests), 1)
        # Which should be a Satellite5DestinationInfo
        dest_info = config_manager.dests.pop()
        self.assertTrue(isinstance(dest_info, Satellite5DestinationInfo), 'The destination info '
                                                                          'we got was not of the '
                                                                          'expected type')
        manager = Manager.fromInfo(self.logger, effective_config, dest_info)
        self.assertTrue(isinstance(manager, Satellite))
        self.assertEqual(dest_info.sat_server, 'sat.example.com')
Beispiel #3
0
    def _create_destinations(self):
        """Populate self.destinations with a list of  list with them

            @param reset: Whether to kill existing destinations or not, defaults
            to false
            @type: bool
        """
        dests = []
        for info in self.dest_to_source_mapper.dests:
            # Dests should already include all destinations we want created
            # at this time. This method will make no assumptions of creating
            # defaults of any kind.
            source_keys = self.dest_to_source_mapper.dest_to_sources_map[info]
            info.name = "destination_%s" % hash(info)
            logger = log.getLogger(name=info.name)
            manager = Manager.fromInfo(logger, self.options, info)
            dest_class = info_to_destination_class[type(info)]
            dest = dest_class(config=info,
                              logger=logger,
                              source_keys=source_keys,
                              options=self.options,
                              source=self.datastore,
                              dest=manager,
                              terminate_event=self.terminate_event,
                              interval=self.options[VW_GLOBAL]['interval'],
                              oneshot=self.options[VW_GLOBAL]['oneshot'],
                              status=self.options[VW_GLOBAL]['status'])
            dests.append(dest)
        return dests
Beispiel #4
0
 def test_per_config_options_encrypted(self, can_write):
     options = Mock()
     options.force_register = True
     can_write.return_value = True
     with tempfile.NamedTemporaryFile() as tmp:
         password.Password.KEYFILE = tmp.name
         config_dict = {
             "sat_server":
             "http://localhost:%s" % TEST_PORT,
             "sat_username":
             "******",
             "sat_encrypted_password":
             hexlify(password.Password.encrypt('password')),
             "type":
             "libvirt",
         }
         config = VirtConfigSection.from_dict(config_dict, 'test', None)
         config.validate()
         dests = DestinationToSourceMapper.parse_dests_from_dict(
             config._values)
         self.assertEqual(len(dests), 1)
         dest_info = dests.pop()
         s = Manager.fromInfo(self.logger, options, dest_info)
         self.assertTrue(isinstance(s, Satellite))
         report = HostGuestAssociationReport(config, self.mapping)
         result = s.hypervisorCheckIn(report, options)
     self.assertTrue("failedUpdate" in result)
     self.assertTrue("created" in result)
     self.assertTrue("updated" in result)
Beispiel #5
0
 def test_satellite_config_cmd(self):
     os.environ = {}
     sys.argv = ["virt-who", "--satellite",
                 "--satellite-server=sat.example.com",
                 "--satellite-username=username",
                 "--satellite-password=password",
                 "--libvirt"]
     logger, effective_config = parse_options()
     config_manager = DestinationToSourceMapper(effective_config)
     # Again there should only be one config parsed out (and one dest)
     self.assertEqual(len(config_manager.configs), 1)
     self.assertEqual(len(config_manager.dests), 1)
     dest_info = config_manager.dests.pop()
     self.assertTrue(isinstance(dest_info, Satellite5DestinationInfo))
     manager = Manager.fromInfo(self.logger, effective_config, dest_info)
     self.assertTrue(isinstance(manager, Satellite))
Beispiel #6
0
 def test_satellite_config_env(self):
     os.environ = {
         "VIRTWHO_SATELLITE": '1',
         "VIRTWHO_SATELLITE_SERVER": 'sat.example.com',
         "VIRTWHO_SATELLITE_USERNAME": '******',
         "VIRTWHO_SATELLITE_PASSWORD": '******',
         "VIRTWHO_LIBVIRT": '1'
     }
     sys.argv = ["virt-who"]
     logger, effective_config = parse_options()
     config_manager = DestinationToSourceMapper(effective_config)
     # Again there should only be one config parsed out (and one dest)
     self.assertEqual(len(config_manager.configs), 1)
     self.assertEqual(len(config_manager.dests), 1)
     dest_info = config_manager.dests.pop()
     self.assertTrue(isinstance(dest_info, Satellite5DestinationInfo))
     manager = Manager.fromInfo(self.logger, effective_config, dest_info)
     self.assertTrue(isinstance(manager, Satellite))
Beispiel #7
0
 def test_per_config_options_encrypted(self, can_write):
     options = Mock()
     options.force_register = True
     can_write.return_value = True
     with tempfile.NamedTemporaryFile() as tmp:
         password.Password.KEYFILE = tmp.name
         config_dict = {
             "sat_server": "http://localhost:%s" % TEST_PORT,
             "sat_username": "******",
             "sat_encrypted_password": hexlify(password.Password.encrypt('password')),
             "type": "libvirt",
         }
         config = VirtConfigSection.from_dict(config_dict, 'test', None)
         config.validate()
         dests = DestinationToSourceMapper.parse_dests_from_dict(config._values)
         self.assertEqual(len(dests), 1)
         dest_info = dests.pop()
         s = Manager.fromInfo(self.logger, options, dest_info)
         self.assertTrue(isinstance(s, Satellite))
         report = HostGuestAssociationReport(config, self.mapping)
         result = s.hypervisorCheckIn(report, options)
     self.assertTrue("failedUpdate" in result)
     self.assertTrue("created" in result)
     self.assertTrue("updated" in result)