def test_should_fail_when_key_is_missing_api300(self): self.mock_ov_client.storage_pools.get_by.return_value = [DICT_DEFAULT_STORAGE_POOL] self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_MISSING_KEY) StoragePoolModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=StoragePoolModule.MSG_MANDATORY_FIELD_MISSING)
def test_should_fail_when_absent_but_storage_pool_exists_api500(self): self.mock_ov_client.api_version = 500 self.mock_ov_client.storage_pools.get_by.return_value = [DICT_DEFAULT_STORAGE_POOL_500] self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_ABSENT_500) StoragePoolModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=StoragePoolModule.MSG_RESOURCE_FOUND)
def test_should_fail_when_key_is_missing_api500(self): self.mock_ov_client.api_version = 500 self.resource.data = DICT_DEFAULT_STORAGE_POOL self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_MISSING_KEY) StoragePoolModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=StoragePoolModule.MSG_MANDATORY_FIELD_MISSING)
def test_should_fail_when_present_but_storage_pool_is_absent_api500(self): self.mock_ov_client.api_version = 500 self.resource.get_by_name.return_value = None self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_500) StoragePoolModule().run() self.mock_ansible_module.fail_json.assert_called_once_with(exception=mock.ANY, msg=StoragePoolModule.MSG_RESOURCE_NOT_FOUND)
def test_should_do_nothing_when_storage_pool_not_exist(self): self.mock_ov_client.storage_pools.get_by.return_value = [] self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_ABSENT) StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=StoragePoolModule.MSG_ALREADY_ABSENT)
def test_should_remove_storage_pool(self): self.mock_ov_client.storage_pools.get_by.return_value = [DICT_DEFAULT_STORAGE_POOL] self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_ABSENT) StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StoragePoolModule.MSG_DELETED )
def test_should_remove_storage_pool(self): self.resource.data = DICT_DEFAULT_STORAGE_POOL self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_ABSENT) StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StoragePoolModule.MSG_DELETED )
def test_should_do_nothing_when_storage_pool_already_exist(self): self.mock_ov_client.storage_pools.get_by.return_value = [DICT_DEFAULT_STORAGE_POOL] self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL) StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=StoragePoolModule.MSG_ALREADY_PRESENT, ansible_facts=dict(storage_pool=DICT_DEFAULT_STORAGE_POOL) )
def test_should_create_new_storage_pool(self): self.mock_ov_client.storage_pools.get_by.return_value = [] self.mock_ov_client.storage_pools.add.return_value = {"name": "name"} self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL) StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StoragePoolModule.MSG_CREATED, ansible_facts=dict(storage_pool={"name": "name"}))
def test_should_do_nothing_when_storage_pool_not_exist(self): self.mock_ov_client.api_version = 500 self.resource.get_by_name.return_value = None self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_ABSENT) StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=StoragePoolModule.MSG_ALREADY_ABSENT, ansible_facts=dict(storage_pool=None) )
def test_update_should_do_nothing_when_storage_pool_is_absent_and_do_not_exists_api500(self): self.mock_ov_client.api_version = 500 self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_ABSENT_500) self.mock_ov_client.storage_pools.get_by.return_value = [] StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=StoragePoolModule.MSG_ALREADY_ABSENT, ansible_facts=dict(storage_pool=None) )
def test_update_should_do_nothing_when_storage_pool_already_exists_and_is_equal_api500(self): self.mock_ov_client.api_version = 500 self.mock_ansible_module.params = yaml.load(YAML_STORAGE_POOL_500) self.resource.data = DICT_DEFAULT_STORAGE_POOL_500 StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=StoragePoolModule.MSG_ALREADY_PRESENT, ansible_facts=dict(storage_pool=DICT_DEFAULT_STORAGE_POOL_500) )
def test_update_when_storage_pool_already_exists_and_is_different_api500(self): self.mock_ov_client.api_version = 500 update_params = yaml.load(YAML_STORAGE_POOL_500) update_params['data']['isManaged'] = False self.mock_ansible_module.params = update_params self.mock_ov_client.storage_pools.get_by.return_value = [DICT_DEFAULT_STORAGE_POOL_500] self.mock_ov_client.storage_pools.update.return_value = update_params StoragePoolModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StoragePoolModule.MSG_UPDATED, ansible_facts=dict(storage_pool=update_params) )