Exemplo n.º 1
0
    def test_add_group_with_members_that_do_not_exist_raises_exception(self):
        from inventory import HostDoesNotExist

        inv = AwxInventory()

        with self.assertRaises(HostDoesNotExist):
            inv.add_group('group1', hosts=['non_existing_host'])
Exemplo n.º 2
0
    def test_add_group_creates_dict(self):

        inv = AwxInventory()

        inv.add_group('group1')

        self.assertIsInstance(inv.groups, dict)
Exemplo n.º 3
0
    def test_add_group_with_members_and_vars(self):

        inv = AwxInventory()

        hosts = ['host1', 'host2']
        for host in hosts:
            inv.add_host(host)

        group_vars = {
            'var1': 'val1',
            'var2': 'val2'
        }

        inv.add_group('group1', group_vars=group_vars, hosts=hosts)

        test_dict = {
            'group1': {
                'hosts': [
                    'host1',
                    'host2'
                ],

                'vars': group_vars

            }
        }

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 4
0
    def test_remove_host_from_group_when_not_in_one_of_the_groups(self):

        inv = AwxInventory()
        inv.add_host('host1')
        inv.add_host('host2')

        inv.add_group('group1', hosts=['host1', 'host2'])
        inv.add_group('group2', hosts=['host1'])

        inv.remove_host('host2')

        test_dict = {
            'group1': {
                'hosts': [
                    'host1'
                ]
            },
            'group2': {
                'hosts': [
                    'host1'
                ]
            }
        }

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 5
0
    def test_add_host_to_group_raises_exception_no_host(self):
        from inventory import HostDoesNotExist

        inv = AwxInventory()

        inv.add_group('group1')

        with self.assertRaises(HostDoesNotExist):
            inv.add_host_to_group('host1', 'group1')
Exemplo n.º 6
0
    def test_add_group_that_already_exist_raises_exception(self):
        from inventory import GroupAlreadyExist

        inv = AwxInventory()

        inv.add_group('group1')

        with self.assertRaises(GroupAlreadyExist):
            inv.add_group('group1')
Exemplo n.º 7
0
    def test_add_group_dict_value(self):

        inv = AwxInventory()

        inv.add_group('group1')

        test_dict = {'group1': {}}

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 8
0
    def test_remove_group(self):
        inv = AwxInventory()

        inv.add_group('group1')
        inv.add_group('group2')

        inv.remove_group('group1')

        test_dict = {'group2': {}}

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 9
0
    def test_add_group_with_vars_dict_value(self):

        inv = AwxInventory()

        test_group_vars = {'var1': 'val1'}

        inv.add_group('group1', group_vars=test_group_vars)

        test_dict = {'group1': {'vars': test_group_vars}}

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 10
0
    def test_add_host_to_group(self):

        inv = AwxInventory()

        inv.add_host('host1')
        inv.add_group('group1')

        inv.add_host_to_group('host1', 'group1')

        test_dict = {'group1': {'hosts': ['host1']}}

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 11
0
    def test_remove_host_from_group(self):

        inv = AwxInventory()
        inv.add_host('host1')
        inv.add_host('host2')

        inv.add_group('group1', hosts=['host1', 'host2'])

        inv.remove_host('host2')

        test_dict = {'group1': {'hosts': ['host1']}}

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 12
0
    def test_add_group_with_hosts(self):

        inv = AwxInventory()

        hosts = ['host1', 'host2']

        for host in hosts:
            inv.add_host(host)

        inv.add_group('group1', hosts=hosts)

        test_dict = {'group1': {'hosts': ['host1', 'host2']}}

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 13
0
    def test_add_group_vars(self):

        inv = AwxInventory()

        inv.add_group('group1')

        test_vars = {
            'var1': 'val1',
            'var2': 'val2',
        }

        inv.add_group_vars('group1', test_vars)

        test_dict = {'group1': {'vars': test_vars}}

        self.assertDictEqual(inv.groups, test_dict)
Exemplo n.º 14
0
    def test_remove_group_with_host_check_hosts_host_removed(self):
        inv = AwxInventory()

        inv.add_host('host1')
        inv.add_host('host2')
        inv.add_host('host3')

        inv.add_group('group1')
        inv.add_group('group2')

        inv.add_host_to_group('host1', 'group1')
        inv.add_host_to_group('host2', 'group2')
        inv.add_host_to_group('host3', 'group1')

        inv.remove_group('group1', delete_host=True)

        test_dict = {'host2': {}}

        self.assertDictEqual(inv.hosts, test_dict)