Пример #1
0
    def test_one_source_to_many_dests(self):
        # This tests that there can be one source that specifies
        # information for different destinations and that the correct mapping
        # is created.
        config_1 = combine_dicts(TestReadingConfigs.source_options_1,
                                 TestReadingConfigs.dest_options_1)

        # NOTE: virt-who today does not support config sections having the same
        # name. Hence the only way to have one source go to multiple
        # destinations (without new config options) is to have two sections
        # with the same information but different section names
        config_options_2 = TestReadingConfigs.source_options_1.copy()
        config_options_2['name'] = 'test2'
        config_2 = combine_dicts(config_options_2,
                                 TestReadingConfigs.dest_options_2)

        expected_dest_1 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_1)
        expected_dest_2 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_2)
        expected_mapping = {
            expected_dest_1: [config_1['name']],
            expected_dest_2: [config_2['name']]  # config_2['name'] ==
            # config_1['name']
        }

        with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
            f.write(
                TestReadingConfigs.dict_to_ini(config_1) +
                TestReadingConfigs.dict_to_ini(config_2))

        manager = DestinationToSourceMapper(
            init_config({}, config_dir=self.config_dir))
        self.assertEqual(manager.dest_to_sources_map, expected_mapping)
Пример #2
0
    def test_many_sources_to_one_dest(self):
        # This tests that there can be multiple configs that specify to
        # report to the same destination
        config_1 = combine_dicts(TestReadingConfigs.source_options_1,
                                 TestReadingConfigs.dest_options_1)
        config_2 = combine_dicts(TestReadingConfigs.source_options_2,
                                 TestReadingConfigs.dest_options_1)
        expected_dest = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_1)

        expected_mapping = {
            expected_dest: [config_1['name'], config_2['name']]
        }

        with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
            f.write(
                TestReadingConfigs.dict_to_ini(config_1) +
                TestReadingConfigs.dict_to_ini(config_2))

        manager = DestinationToSourceMapper(
            init_config({}, config_dir=self.config_dir))
        self.assertEqual(manager.dests, set([expected_dest]))
        self.assertEqual(manager.sources,
                         set([config_1['name'], config_2['name']]))

        self.assertEqual(manager.dest_to_sources_map, expected_mapping)
Пример #3
0
    def test_many_sources_to_many_dests(self):
        config_1 = combine_dicts(TestReadingConfigs.source_options_1,
                                 TestReadingConfigs.dest_options_1)
        config_2 = combine_dicts(TestReadingConfigs.source_options_2,
                                 TestReadingConfigs.dest_options_2)

        # Create another source config that is slightly different
        source_3_options = TestReadingConfigs.source_options_2.copy()
        source_3_options['name'] = 'test3'
        source_4_options = TestReadingConfigs.source_options_1.copy()
        source_4_options['name'] = 'test4'

        # Create another dest config that is slightly different
        dest_options_3 = TestReadingConfigs.dest_options_2.copy()
        dest_options_3['owner'] = 'some_cool_owner_person'

        config_3 = combine_dicts(source_3_options,
                                 TestReadingConfigs.dest_options_2)

        config_4 = combine_dicts(source_4_options, dest_options_3)

        expected_dest_1 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_1)
        expected_dest_2 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_2)
        expected_dest_3 = Satellite6DestinationInfo(**dest_options_3)

        expected_mapping = {
            expected_dest_1: [config_1['name']],
            expected_dest_2: [config_2['name'], config_3['name']],
            expected_dest_3: [config_4['name']]
        }

        with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
            f.write(
                TestReadingConfigs.dict_to_ini(config_1) +
                TestReadingConfigs.dict_to_ini(config_2) +
                TestReadingConfigs.dict_to_ini(config_3) +
                TestReadingConfigs.dict_to_ini(config_4))

        manager = DestinationToSourceMapper(
            init_config({}, config_dir=self.config_dir))
        self.assertEqual(manager.dest_to_sources_map, expected_mapping)
Пример #4
0
    def test_two_sources_to_two_dests(self):
        config_1 = combine_dicts(TestReadingConfigs.source_options_1,
                                 TestReadingConfigs.dest_options_1)
        config_2 = combine_dicts(TestReadingConfigs.source_options_2,
                                 TestReadingConfigs.dest_options_2)
        expected_dest_1 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_1)
        expected_dest_2 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_2)
        expected_mapping = {
            expected_dest_1: [config_1['name']],
            expected_dest_2: [config_2['name']]
        }

        with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
            f.write(
                TestReadingConfigs.dict_to_ini(config_1) +
                TestReadingConfigs.dict_to_ini(config_2))

        manager = ConfigManager(self.logger, self.config_dir)
        self.assertEquals(manager.dest_to_sources_map, expected_mapping)
Пример #5
0
    def test_one_source_to_one_dest(self):
        config_1 = combine_dicts(TestReadingConfigs.source_options_1,
                                 TestReadingConfigs.dest_options_1)
        expected_dest_1 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_1)
        expected_mapping = {expected_dest_1: [config_1['name']]}

        with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
            f.write(TestReadingConfigs.dict_to_ini(config_1))

        manager = DestinationToSourceMapper(
            init_config({}, config_dir=self.config_dir))
        self.assertEqual(manager.dest_to_sources_map, expected_mapping)
Пример #6
0
    def testMultipleConfigFiles(self):
        config_1 = combine_dicts(TestReadingConfigs.source_options_1,
                                 TestReadingConfigs.dest_options_1)
        config_2 = combine_dicts(TestReadingConfigs.source_options_2,
                                 TestReadingConfigs.dest_options_2)

        with open(os.path.join(self.config_dir, "test1.conf"), "w") as f:
            f.write(TestReadingConfigs.dict_to_ini(config_1))
        with open(os.path.join(self.config_dir, "test2.conf"), "w") as f:
            f.write(TestReadingConfigs.dict_to_ini(config_2))

        expected_dest_1 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_1)
        expected_dest_2 = Satellite6DestinationInfo(
            **TestReadingConfigs.dest_options_2)

        expected_mapping = {
            expected_dest_1: [config_1['name']],
            expected_dest_2: [config_2['name']]
        }

        manager = DestinationToSourceMapper(
            init_config({}, config_dir=self.config_dir))
        self.assertEqual(len(manager.configs), 2)
        self.assertEqual(manager.dest_to_sources_map, expected_mapping)
        self.assertEqual(manager.dests, set([expected_dest_1,
                                             expected_dest_2]))
        self.assertEqual(manager.sources,
                         set([config_1['name'], config_2['name']]))

        result1 = manager.configs[0][1]
        result2 = manager.configs[1][1]

        self.assertIn(result1.name, ("test1", "test2"))
        if result1.name == "test2":
            result2, result1 = result1, result2

        self.assert_config_contains_all(result1, config_1)
        self.assert_config_contains_all(result2, config_2)