def test_get_object_fails(self, connection_mock, load_mock): swiftapi = swift.SwiftAPI() swift_mock = connection_mock.return_value.object_store swift_mock.download_object.side_effect = os_exc.SDKException self.assertRaises(utils.Error, swiftapi.get_object, 'object') swift_mock.download_object.assert_called_once_with( 'object', container='ironic-inspector')
def test_get_object_fails(self, connection_mock, load_mock, opts_mock): swiftapi = swift.SwiftAPI() connection_obj_mock = connection_mock.return_value connection_obj_mock.get_object.side_effect = self.swift_exception self.assertRaises(utils.Error, swiftapi.get_object, 'object') connection_obj_mock.get_object.assert_called_once_with( 'ironic-inspector', 'object')
def test___init__(self, connection_mock, load_mock, opts_mock, adapter_mock): fake_endpoint = "http://localhost:6000" adapter_mock.return_value.get_endpoint.return_value = fake_endpoint swift.SwiftAPI() connection_mock.assert_called_once_with( session=load_mock.return_value, os_options={'object_storage_url': fake_endpoint})
def test_create_object_create_container_fails(self, connection_mock, load_mock): swiftapi = swift.SwiftAPI() swift_mock = connection_mock.return_value.object_store swift_mock.create_container.side_effect = os_exc.SDKException self.assertRaises(utils.Error, swiftapi.create_object, 'object', 'some-string-data') swift_mock.create_container.assert_called_once_with('ironic-inspector') self.assertFalse(swift_mock.create_object.called)
def test_get_object(self, connection_mock, load_mock): swiftapi = swift.SwiftAPI() swift_mock = connection_mock.return_value.object_store swift_obj = swiftapi.get_object('object') swift_mock.download_object.assert_called_once_with( 'object', container='ironic-inspector') self.assertIs(swift_mock.download_object.return_value, swift_obj)
def test_create_object_create_container_fails(self, connection_mock, load_mock, opts_mock): swiftapi = swift.SwiftAPI() connection_obj_mock = connection_mock.return_value connection_obj_mock.put_container.side_effect = self.swift_exception self.assertRaises(utils.Error, swiftapi.create_object, 'object', 'some-string-data') connection_obj_mock.put_container.assert_called_once_with('ironic-' 'inspector') self.assertFalse(connection_obj_mock.put_object.called)
def test___init__defaults(self, connection_mock): swift.SwiftAPI() params = {'retries': 2, 'user': '******', 'tenant_name': 'tenant', 'key': 'password', 'authurl': 'http://authurl/v2.0', 'auth_version': '2', 'os_options': {'service_type': 'object-store', 'endpoint_type': 'internalURL'}} connection_mock.assert_called_once_with(**params)
def test_get_object_fails(self, connection_mock): swiftapi = swift.SwiftAPI(user=CONF.swift.username, tenant_name=CONF.swift.tenant_name, key=CONF.swift.password, auth_url=CONF.swift.os_auth_url, auth_version=CONF.swift.os_auth_version) connection_obj_mock = connection_mock.return_value connection_obj_mock.get_object.side_effect = self.swift_exception self.assertRaises(utils.Error, swiftapi.get_object, 'object') connection_obj_mock.get_object.assert_called_once_with( 'ironic-inspector', 'object')
def test_get_object(self, connection_mock, load_mock, opts_mock): swiftapi = swift.SwiftAPI() connection_obj_mock = connection_mock.return_value expected_obj = self.data connection_obj_mock.get_object.return_value = ('headers', expected_obj) swift_obj = swiftapi.get_object('object') connection_obj_mock.get_object.assert_called_once_with( 'ironic-inspector', 'object') self.assertEqual(expected_obj, swift_obj)
def test_create_object(self, connection_mock, load_mock, opts_mock): swiftapi = swift.SwiftAPI() connection_obj_mock = connection_mock.return_value connection_obj_mock.put_object.return_value = 'object-uuid' object_uuid = swiftapi.create_object('object', 'some-string-data') connection_obj_mock.put_container.assert_called_once_with('ironic-' 'inspector') connection_obj_mock.put_object.assert_called_once_with( 'ironic-inspector', 'object', 'some-string-data', headers=None) self.assertEqual('object-uuid', object_uuid)
def test_create_object_create_container_fails(self, connection_mock): swiftapi = swift.SwiftAPI(user=CONF.swift.username, tenant_name=CONF.swift.tenant_name, key=CONF.swift.password, auth_url=CONF.swift.os_auth_url, auth_version=CONF.swift.os_auth_version) connection_obj_mock = connection_mock.return_value connection_obj_mock.put_container.side_effect = self.swift_exception self.assertRaises(utils.Error, swiftapi.create_object, 'object', 'some-string-data') connection_obj_mock.put_container.assert_called_once_with('ironic-' 'inspector') self.assertFalse(connection_obj_mock.put_object.called)
def test_create_object_with_delete_after(self, connection_mock, load_mock): swift.CONF.set_override('delete_after', 60, group='swift') swiftapi = swift.SwiftAPI() swift_mock = connection_mock.return_value.object_store swift_mock.create_object.return_value = 'object-uuid' object_uuid = swiftapi.create_object('object', 'some-string-data') swift_mock.create_container.assert_called_once_with('ironic-inspector') swift_mock.create_object.assert_called_once_with( 'ironic-inspector', 'object', data='some-string-data', headers={'X-Delete-After': 60}) self.assertEqual('object-uuid', object_uuid)
def test_get_object(self, connection_mock): swiftapi = swift.SwiftAPI(user=CONF.swift.username, tenant_name=CONF.swift.tenant_name, key=CONF.swift.password, auth_url=CONF.swift.os_auth_url, auth_version=CONF.swift.os_auth_version) connection_obj_mock = connection_mock.return_value expected_obj = self.data connection_obj_mock.get_object.return_value = ('headers', expected_obj) swift_obj = swiftapi.get_object('object') connection_obj_mock.get_object.assert_called_once_with( 'ironic-inspector', 'object') self.assertEqual(expected_obj, swift_obj)
def test_create_object(self, connection_mock): swiftapi = swift.SwiftAPI(user=CONF.swift.username, tenant_name=CONF.swift.tenant_name, key=CONF.swift.password, auth_url=CONF.swift.os_auth_url, auth_version=CONF.swift.os_auth_version) connection_obj_mock = connection_mock.return_value connection_obj_mock.put_object.return_value = 'object-uuid' object_uuid = swiftapi.create_object('object', 'some-string-data') connection_obj_mock.put_container.assert_called_once_with('ironic-' 'inspector') connection_obj_mock.put_object.assert_called_once_with( 'ironic-inspector', 'object', 'some-string-data', headers=None) self.assertEqual('object-uuid', object_uuid)
def test___init__(self, connection_mock, load_mock, opts_mock): swift_url = 'http://swiftapi' token = 'secret_token' mock_sess = mock.Mock() mock_sess.get_token.return_value = token mock_sess.get_endpoint.return_value = swift_url mock_sess.verify = False load_mock.return_value = mock_sess swift.SwiftAPI() params = { 'retries': 2, 'preauthurl': swift_url, 'preauthtoken': token, 'insecure': True } connection_mock.assert_called_once_with(**params) mock_sess.get_endpoint.assert_called_once_with( service_type='object-store', endpoint_type='internalURL', region_name='somewhere')
def _store_extra_hardware(self, name, data): """Handles storing the extra hardware data from the ramdisk""" swift_api = swift.SwiftAPI() swift_api.create_object(name, data)
def test___init__(self, connection_mock, load_mock): swift.SwiftAPI() connection_mock.assert_called_once_with(session=load_mock.return_value, oslo_conf=swift.CONF)