def test_should_get_storage_system_pools_by_ip_hostname( self, mock_ansible_module, mock_ov_client_from_json_file): mock_ov_instance = mock.Mock() mock_ov_instance.storage_systems.get_by_ip_hostname.return_value = { "ip_hostname": "10.0.0.0", "uri": "uri" } mock_ov_instance.storage_systems.get_storage_pools.return_value = { "name": "Storage Pool" } mock_ov_client_from_json_file.return_value = mock_ov_instance mock_ansible_instance = create_ansible_mock( PARAMS_GET_POOL_BY_IP_HOSTNAME) mock_ansible_module.return_value = mock_ansible_instance StorageSystemFactsModule().run() mock_ansible_instance.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_system_pools=({ "name": "Storage Pool" }), storage_systems={ "ip_hostname": "10.0.0.0", "uri": "uri" }))
def test_should_load_config_from_file(self, mock_ansible_module, mock_ov_client_from_env_vars, mock_ov_client_from_json_file): mock_ov_instance = mock.Mock() mock_ov_client_from_json_file.return_value = mock_ov_instance mock_ansible_instance = create_ansible_mock({'config': 'config.json'}) mock_ansible_module.return_value = mock_ansible_instance StorageSystemFactsModule() mock_ov_client_from_json_file.assert_called_once_with('config.json') mock_ov_client_from_env_vars.not_been_called()
def test_should_get_storage_system_by_ip_hostname(self): self.storage_systems.get_by_ip_hostname.return_value = { "ip_hostname": "10.0.0.0" } self.mock_ansible_module.params = PARAMS_GET_BY_IP_HOSTNAME StorageSystemFactsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_systems=({ "ip_hostname": "10.0.0.0" })))
def test_should_get_all_storage_system(self): self.storage_systems.get_all.return_value = { "name": "Storage System Name" } self.mock_ansible_module.params = PARAMS_GET_ALL StorageSystemFactsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_systems=({ "name": "Storage System Name" })))
def test_should_fail_when_get_all_raises_exception( self, mock_ansible_module, mock_ov_client_from_json_file): mock_ov_instance = mock.Mock() mock_ov_instance.storage_systems.get_all.side_effect = Exception( ERROR_MSG) mock_ov_client_from_json_file.return_value = mock_ov_instance mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL) mock_ansible_module.return_value = mock_ansible_instance StorageSystemFactsModule().run() mock_ansible_instance.fail_json.assert_called_once()
def test_should_get_all_host_types(self): self.storage_systems.get_host_types.return_value = HOST_TYPES self.storage_systems.get_all.return_value = [{ "name": "Storage System Name" }] self.mock_ansible_module.params = PARAMS_GET_HOST_TYPES StorageSystemFactsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_system_host_types=HOST_TYPES, storage_systems=[{ "name": "Storage System Name" }]))
def test_should_get_all_storage_system(self, mock_ansible_module, mock_ov_client_from_json_file): mock_ov_instance = mock.Mock() mock_ov_instance.storage_systems.get_all.return_value = { "name": "Storage System Name" } mock_ov_client_from_json_file.return_value = mock_ov_instance mock_ansible_instance = create_ansible_mock(PARAMS_GET_ALL) mock_ansible_module.return_value = mock_ansible_instance StorageSystemFactsModule().run() mock_ansible_instance.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_systems=({ "name": "Storage System Name" })))
def test_should_get_storage_pools_system_by_name(self): self.storage_systems.get_by_name.return_value = { "name": "Storage System Name", "uri": "uri" } self.storage_systems.get_storage_pools.return_value = { "name": "Storage Pool" } self.mock_ansible_module.params = PARAMS_GET_POOL_BY_NAME StorageSystemFactsModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_system_pools=({ "name": "Storage Pool" }), storage_systems={ "name": "Storage System Name", "uri": "uri" }))
def test_should_get_all_host_types(self, mock_ansible_module, mock_ov_client_from_json_file): mock_ov_instance = mock.Mock() mock_ov_instance.storage_systems.get_host_types.return_value = HOST_TYPES mock_ov_instance.storage_systems.get_all.return_value = [{ "name": "Storage System Name" }] mock_ov_client_from_json_file.return_value = mock_ov_instance mock_ansible_instance = create_ansible_mock(PARAMS_GET_HOST_TYPES) mock_ansible_module.return_value = mock_ansible_instance StorageSystemFactsModule().run() mock_ansible_instance.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(storage_system_host_types=HOST_TYPES, storage_systems=[{ "name": "Storage System Name" }]))