Esempio n. 1
0
    def test_should_do_nothing_when_id_pools_ipv4_subnet_not_exist(self):
        self.resource.get_by_field.return_value = None

        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        IdPoolsIpv4SubnetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False, msg=IdPoolsIpv4SubnetModule.MSG_ALREADY_ABSENT)
Esempio n. 2
0
    def test_should_remove_id_pools_ipv4_subnet(self):
        self.resource.data = DEFAULT_SUBNET_TEMPLATE
        self.resource.get_by_field.return_value = self.resource

        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        IdPoolsIpv4SubnetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True, msg=IdPoolsIpv4SubnetModule.MSG_DELETED)
Esempio n. 3
0
    def test_should_not_update_when_data_is_equals(self):
        self.resource.data = DEFAULT_SUBNET_TEMPLATE
        self.resource.get_by_field.return_value = self.resource

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        IdPoolsIpv4SubnetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=IdPoolsIpv4SubnetModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(id_pools_ipv4_subnet=DEFAULT_SUBNET_TEMPLATE))
Esempio n. 4
0
    def test_should_get_the_same_resource_by_uri(self):
        self.resource.data = DEFAULT_SUBNET_TEMPLATE
        self.resource.get_by_uri.return_value = self.resource

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT_WITH_URI

        IdPoolsIpv4SubnetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=IdPoolsIpv4SubnetModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(id_pools_ipv4_subnet=DEFAULT_SUBNET_TEMPLATE))
Esempio n. 5
0
    def test_should_create_new_id_pools_ipv4_subnet(self):
        self.resource.get_by_field.return_value = None
        self.resource.create.return_value = self.resource

        self.resource.data = DEFAULT_SUBNET_TEMPLATE

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        IdPoolsIpv4SubnetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=IdPoolsIpv4SubnetModule.MSG_CREATED,
            ansible_facts=dict(id_pools_ipv4_subnet=DEFAULT_SUBNET_TEMPLATE))
Esempio n. 6
0
    def test_update_when_data_has_modified_attributes(self):
        data_merged = DEFAULT_SUBNET_TEMPLATE.copy()
        data_merged['domain'] = 'diffdomain.com'

        self.resource.data = data_merged
        self.resource.get_by_field.return_value = self.resource
        self.resource.update.return_value = data_merged

        self.mock_ansible_module.params = PARAMS_WITH_CHANGES

        IdPoolsIpv4SubnetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=IdPoolsIpv4SubnetModule.MSG_UPDATED,
            ansible_facts=dict(id_pools_ipv4_subnet=data_merged))
Esempio n. 7
0
    def test_should_allocate_when_valid_ids_present(self):
        data_merged = DEFAULT_SUBNET_TEMPLATE.copy()

        data_merged['count'] = 2
        data_merged['allocatorUri'] = '/rest/fake'
        self.resource.data = data_merged
        self.resource.get_by_field.return_value = self.resource
        self.resource.allocate.return_value = {'idList': ['172.9.0.1', '172.9.0.2']}

        self.mock_ansible_module.params = PARAMS_FOR_ALLOCATE

        IdPoolsIpv4SubnetModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=IdPoolsIpv4SubnetModule.MSG_ALLOCATE,
            ansible_facts=dict(id_pools_ipv4_subnet={'idList': ['172.9.0.1', '172.9.0.2']})
        )