def test_should_do_nothing_when_storage_system_not_exist(self): self.resource.get_by_ip_hostname.return_value = [] self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_ABSENT) StorageSystemModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=StorageSystemModule.MSG_ALREADY_ABSENT)
def test_should_remove_storage_system(self): self.resource.get_by_ip_hostname.return_value = DICT_DEFAULT_STORAGE_SYSTEM self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_ABSENT) StorageSystemModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StorageSystemModule.MSG_DELETED)
def test_should_fail_when_credentials_attribute_is_missing(self): self.resource.get_by_name.return_value = [] self.mock_ansible_module.params = yaml.load( YAML_STORAGE_SYSTEM_BY_NAME) StorageSystemModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( msg=StorageSystemModule.MSG_CREDENTIALS_MANDATORY)
def test_should_fail_with_missing_required_attributes(self): self.mock_ansible_module.params = {"state": "present", "config": "config", "data": {"field": "invalid"}} StorageSystemModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( msg=StorageSystemModule.MSG_MANDATORY_FIELDS_MISSING )
def test_should_add_new_storage_system_with_credentials_from_api300(self): self.resource.get_by_ip_hostname.return_value = None obj = mock.Mock() obj.data = DICT_DEFAULT_STORAGE_SYSTEM self.resource.add.return_value = obj self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM) StorageSystemModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StorageSystemModule.MSG_ADDED, ansible_facts=dict(storage_system=DICT_DEFAULT_STORAGE_SYSTEM))
def test_should_not_update_when_data_is_equals(self): self.resource.get_by_ip_hostname.return_value = DICT_DEFAULT_STORAGE_SYSTEM self.resource.update.return_value = {"name": "name"} self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM) StorageSystemModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=StorageSystemModule.MSG_ALREADY_PRESENT, ansible_facts=dict(storage_system=DICT_DEFAULT_STORAGE_SYSTEM))
def test_should_create_new_storage_system(self): self.resource.get_by_ip_hostname.return_value = None self.resource.add.return_value = {"name": "name"} self.resource.update.return_value = {"name": "name"} self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM) StorageSystemModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StorageSystemModule.MSG_ADDED, ansible_facts=dict(storage_system={"name": "name"}))
def test_should_not_update_when_data_is_equals_using_name(self): dict_by_name = yaml.load(YAML_STORAGE_SYSTEM_BY_NAME)["data"] self.resource.get_by_name.return_value = dict_by_name self.mock_ansible_module.params = yaml.load( YAML_STORAGE_SYSTEM_BY_NAME) StorageSystemModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=StorageSystemModule.MSG_ALREADY_PRESENT, ansible_facts=dict(storage_system=dict_by_name.copy()))
def test_update_when_data_has_modified_attributes(self): data_merged = DICT_DEFAULT_STORAGE_SYSTEM.copy() data_merged['credentials']['newIp_hostname'] = '10.10.10.10' self.resource.get_by_ip_hostname.return_value = DICT_DEFAULT_STORAGE_SYSTEM self.resource.update.return_value = data_merged self.mock_ansible_module.params = yaml.load( YAML_STORAGE_SYSTEM_CHANGES) StorageSystemModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StorageSystemModule.MSG_UPDATED, ansible_facts=dict(storage_system=data_merged))
def test_update_when_data_has_modified_attributes_when_api500(self): self.mock_ov_client.api_version = 500 data_merged = DICT_DEFAULT_STORAGE_SYSTEM_500.copy() data_merged['credentials']['newHostname'] = '10.10.10.10' obj = mock.Mock() obj.data = DICT_DEFAULT_STORAGE_SYSTEM_500 self.resource.get_by_hostname.return_value = obj self.resource.update.return_value = data_merged self.mock_ansible_module.params = yaml.load( YAML_STORAGE_SYSTEM_CHANGES_500) StorageSystemModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StorageSystemModule.MSG_UPDATED, ansible_facts=dict(storage_system=data_merged))
def test_should_add_new_storage_system_with_credentials_from_api500(self): self.mock_ov_client.api_version = 500 self.resource.get_by_hostname.return_value = None self.resource.add.return_value = {"name": "name"} self.resource.update.return_value = {"name": "name"} self.mock_ansible_module.params = yaml.load(YAML_STORAGE_SYSTEM_500) StorageSystemModule().run() self.resource.add.assert_called_once_with({ 'username': '******', 'password': '******', 'hostname': '10.0.0.0', 'family': 'StoreServ' }) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=StorageSystemModule.MSG_ADDED, ansible_facts=dict(storage_system={"name": "name"}))