diff options
Diffstat (limited to 'tempest_lib/tests')
62 files changed, 0 insertions, 7623 deletions
diff --git a/tempest_lib/tests/__init__.py b/tempest_lib/tests/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/base.py b/tempest_lib/tests/base.py deleted file mode 100644 index fe9268e..0000000 --- a/tempest_lib/tests/base.py +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 2013 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import mock -from oslotest import base -from oslotest import moxstubout - - -class TestCase(base.BaseTestCase): - - def setUp(self): - super(TestCase, self).setUp() - mox_fixture = self.useFixture(moxstubout.MoxStubout()) - self.mox = mox_fixture.mox - self.stubs = mox_fixture.stubs - - def patch(self, target, **kwargs): - """Returns a started `mock.patch` object for the supplied target. - - The caller may then call the returned patcher to create a mock object. - - The caller does not need to call stop() on the returned - patcher object, as this method automatically adds a cleanup - to the test class to stop the patcher. - - :param target: String module.class or module.object expression to patch - :param **kwargs: Passed as-is to `mock.patch`. See mock documentation - for details. - """ - p = mock.patch(target, **kwargs) - m = p.start() - self.addCleanup(p.stop) - return m diff --git a/tempest_lib/tests/cli/__init__.py b/tempest_lib/tests/cli/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/cli/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/cli/test_command_failed.py b/tempest_lib/tests/cli/test_command_failed.py deleted file mode 100644 index 17543e9..0000000 --- a/tempest_lib/tests/cli/test_command_failed.py +++ /dev/null @@ -1,30 +0,0 @@ -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib import exceptions -from tempest_lib.tests import base - - -class TestOutputParser(base.TestCase): - - def test_command_failed_exception(self): - returncode = 1 - cmd = "foo" - stdout = "output" - stderr = "error" - try: - raise exceptions.CommandFailed(returncode, cmd, stdout, stderr) - except exceptions.CommandFailed as e: - self.assertIn(str(returncode), str(e)) - self.assertIn(cmd, str(e)) - self.assertIn(stdout, str(e)) - self.assertIn(stderr, str(e)) diff --git a/tempest_lib/tests/cli/test_execute.py b/tempest_lib/tests/cli/test_execute.py deleted file mode 100644 index c86f190..0000000 --- a/tempest_lib/tests/cli/test_execute.py +++ /dev/null @@ -1,37 +0,0 @@ -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -from tempest_lib.cli import base as cli_base -from tempest_lib import exceptions -from tempest_lib.tests import base - - -class TestExecute(base.TestCase): - def test_execute_success(self): - result = cli_base.execute("/bin/ls", action="tempest_lib", - flags="-l -a") - self.assertIsInstance(result, str) - self.assertIn("__init__.py", result) - - def test_execute_failure(self): - result = cli_base.execute("/bin/ls", action="tempest_lib", - flags="--foobar", merge_stderr=True, - fail_ok=True) - self.assertIsInstance(result, str) - self.assertIn("--foobar", result) - - def test_execute_failure_raise_exception(self): - self.assertRaises(exceptions.CommandFailed, cli_base.execute, - "/bin/ls", action="tempest_lib", flags="--foobar", - merge_stderr=True) diff --git a/tempest_lib/tests/cli/test_output_parser.py b/tempest_lib/tests/cli/test_output_parser.py deleted file mode 100644 index 3aa7e91..0000000 --- a/tempest_lib/tests/cli/test_output_parser.py +++ /dev/null @@ -1,177 +0,0 @@ -# Copyright 2014 NEC Corporation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -from tempest_lib.cli import output_parser -from tempest_lib import exceptions -from tempest_lib.tests import base - - -class TestOutputParser(base.TestCase): - OUTPUT_LINES = """ -+----+------+---------+ -| ID | Name | Status | -+----+------+---------+ -| 11 | foo | BUILD | -| 21 | bar | ERROR | -| 31 | bee | None | -+----+------+---------+ -""" - OUTPUT_LINES2 = """ -+----+-------+---------+ -| ID | Name2 | Status2 | -+----+-------+---------+ -| 41 | aaa | SSSSS | -| 51 | bbb | TTTTT | -| 61 | ccc | AAAAA | -+----+-------+---------+ -""" - - EXPECTED_TABLE = {'headers': ['ID', 'Name', 'Status'], - 'values': [['11', 'foo', 'BUILD'], - ['21', 'bar', 'ERROR'], - ['31', 'bee', 'None']]} - EXPECTED_TABLE2 = {'headers': ['ID', 'Name2', 'Status2'], - 'values': [['41', 'aaa', 'SSSSS'], - ['51', 'bbb', 'TTTTT'], - ['61', 'ccc', 'AAAAA']]} - - def test_table_with_normal_values(self): - actual = output_parser.table(self.OUTPUT_LINES) - self.assertIsInstance(actual, dict) - self.assertEqual(self.EXPECTED_TABLE, actual) - - def test_table_with_list(self): - output_lines = self.OUTPUT_LINES.split('\n') - actual = output_parser.table(output_lines) - self.assertIsInstance(actual, dict) - self.assertEqual(self.EXPECTED_TABLE, actual) - - def test_table_with_invalid_line(self): - output_lines = self.OUTPUT_LINES + "aaaa" - actual = output_parser.table(output_lines) - self.assertIsInstance(actual, dict) - self.assertEqual(self.EXPECTED_TABLE, actual) - - def test_tables_with_normal_values(self): - output_lines = ('test' + self.OUTPUT_LINES + - 'test2' + self.OUTPUT_LINES2) - expected = [{'headers': self.EXPECTED_TABLE['headers'], - 'label': 'test', - 'values': self.EXPECTED_TABLE['values']}, - {'headers': self.EXPECTED_TABLE2['headers'], - 'label': 'test2', - 'values': self.EXPECTED_TABLE2['values']}] - actual = output_parser.tables(output_lines) - self.assertIsInstance(actual, list) - self.assertEqual(expected, actual) - - def test_tables_with_invalid_values(self): - output_lines = ('test' + self.OUTPUT_LINES + - 'test2' + self.OUTPUT_LINES2 + '\n') - expected = [{'headers': self.EXPECTED_TABLE['headers'], - 'label': 'test', - 'values': self.EXPECTED_TABLE['values']}, - {'headers': self.EXPECTED_TABLE2['headers'], - 'label': 'test2', - 'values': self.EXPECTED_TABLE2['values']}] - actual = output_parser.tables(output_lines) - self.assertIsInstance(actual, list) - self.assertEqual(expected, actual) - - def test_tables_with_invalid_line(self): - output_lines = ('test' + self.OUTPUT_LINES + - 'test2' + self.OUTPUT_LINES2 + - '+----+-------+---------+') - expected = [{'headers': self.EXPECTED_TABLE['headers'], - 'label': 'test', - 'values': self.EXPECTED_TABLE['values']}, - {'headers': self.EXPECTED_TABLE2['headers'], - 'label': 'test2', - 'values': self.EXPECTED_TABLE2['values']}] - - actual = output_parser.tables(output_lines) - self.assertIsInstance(actual, list) - self.assertEqual(expected, actual) - - LISTING_OUTPUT = """ -+----+ -| ID | -+----+ -| 11 | -| 21 | -| 31 | -+----+ -""" - - def test_listing(self): - expected = [{'ID': '11'}, {'ID': '21'}, {'ID': '31'}] - actual = output_parser.listing(self.LISTING_OUTPUT) - self.assertIsInstance(actual, list) - self.assertEqual(expected, actual) - - def test_details_multiple_with_invalid_line(self): - self.assertRaises(exceptions.InvalidStructure, - output_parser.details_multiple, - self.OUTPUT_LINES) - - DETAILS_LINES1 = """First Table -+----------+--------+ -| Property | Value | -+----------+--------+ -| foo | BUILD | -| bar | ERROR | -| bee | None | -+----------+--------+ -""" - DETAILS_LINES2 = """Second Table -+----------+--------+ -| Property | Value | -+----------+--------+ -| aaa | VVVVV | -| bbb | WWWWW | -| ccc | XXXXX | -+----------+--------+ -""" - - def test_details_with_normal_line_label_false(self): - expected = {'foo': 'BUILD', 'bar': 'ERROR', 'bee': 'None'} - actual = output_parser.details(self.DETAILS_LINES1) - self.assertEqual(expected, actual) - - def test_details_with_normal_line_label_true(self): - expected = {'__label': 'First Table', - 'foo': 'BUILD', 'bar': 'ERROR', 'bee': 'None'} - actual = output_parser.details(self.DETAILS_LINES1, with_label=True) - self.assertEqual(expected, actual) - - def test_details_multiple_with_normal_line_label_false(self): - expected = [{'foo': 'BUILD', 'bar': 'ERROR', 'bee': 'None'}, - {'aaa': 'VVVVV', 'bbb': 'WWWWW', 'ccc': 'XXXXX'}] - actual = output_parser.details_multiple(self.DETAILS_LINES1 + - self.DETAILS_LINES2) - self.assertIsInstance(actual, list) - self.assertEqual(expected, actual) - - def test_details_multiple_with_normal_line_label_true(self): - expected = [{'__label': 'First Table', - 'foo': 'BUILD', 'bar': 'ERROR', 'bee': 'None'}, - {'__label': 'Second Table', - 'aaa': 'VVVVV', 'bbb': 'WWWWW', 'ccc': 'XXXXX'}] - actual = output_parser.details_multiple(self.DETAILS_LINES1 + - self.DETAILS_LINES2, - with_label=True) - self.assertIsInstance(actual, list) - self.assertEqual(expected, actual) diff --git a/tempest_lib/tests/common/__init__.py b/tempest_lib/tests/common/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/common/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/common/utils/__init__.py b/tempest_lib/tests/common/utils/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/common/utils/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/common/utils/test_data_utils.py b/tempest_lib/tests/common/utils/test_data_utils.py deleted file mode 100644 index 2d7b8fc..0000000 --- a/tempest_lib/tests/common/utils/test_data_utils.py +++ /dev/null @@ -1,162 +0,0 @@ -# Copyright 2014 NEC Corporation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import netaddr - -from tempest_lib.common.utils import data_utils -from tempest_lib.tests import base - - -class TestDataUtils(base.TestCase): - - def test_rand_uuid(self): - actual = data_utils.rand_uuid() - self.assertIsInstance(actual, str) - self.assertRegexpMatches(actual, "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]" - "{4}-[0-9a-f]{4}-[0-9a-f]{12}$") - actual2 = data_utils.rand_uuid() - self.assertNotEqual(actual, actual2) - - def test_rand_uuid_hex(self): - actual = data_utils.rand_uuid_hex() - self.assertIsInstance(actual, str) - self.assertRegexpMatches(actual, "^[0-9a-f]{32}$") - - actual2 = data_utils.rand_uuid_hex() - self.assertNotEqual(actual, actual2) - - def test_rand_name(self): - actual = data_utils.rand_name() - self.assertIsInstance(actual, str) - actual2 = data_utils.rand_name() - self.assertNotEqual(actual, actual2) - - actual = data_utils.rand_name('foo') - self.assertTrue(actual.startswith('foo')) - actual2 = data_utils.rand_name('foo') - self.assertTrue(actual.startswith('foo')) - self.assertNotEqual(actual, actual2) - - def test_rand_name_with_prefix(self): - actual = data_utils.rand_name(prefix='prefix-str') - self.assertIsInstance(actual, str) - self.assertRegexpMatches(actual, "^prefix-str-") - actual2 = data_utils.rand_name(prefix='prefix-str') - self.assertNotEqual(actual, actual2) - - def test_rand_password(self): - actual = data_utils.rand_password() - self.assertIsInstance(actual, str) - self.assertRegexpMatches(actual, "[A-Za-z0-9~!@#$%^&*_=+]{15,}") - actual2 = data_utils.rand_password() - self.assertNotEqual(actual, actual2) - - def test_rand_password_with_len(self): - actual = data_utils.rand_password(8) - self.assertIsInstance(actual, str) - self.assertEqual(len(actual), 8) - self.assertRegexpMatches(actual, "[A-Za-z0-9~!@#$%^&*_=+]{8}") - actual2 = data_utils.rand_password(8) - self.assertNotEqual(actual, actual2) - - def test_rand_password_with_len_2(self): - actual = data_utils.rand_password(2) - self.assertIsInstance(actual, str) - self.assertEqual(len(actual), 3) - self.assertRegexpMatches(actual, "[A-Za-z0-9~!@#$%^&*_=+]{3}") - actual2 = data_utils.rand_password(2) - self.assertNotEqual(actual, actual2) - - def test_rand_url(self): - actual = data_utils.rand_url() - self.assertIsInstance(actual, str) - self.assertRegexpMatches(actual, "^https://url-[0-9]*\.com$") - actual2 = data_utils.rand_url() - self.assertNotEqual(actual, actual2) - - def test_rand_int(self): - actual = data_utils.rand_int_id() - self.assertIsInstance(actual, int) - - actual2 = data_utils.rand_int_id() - self.assertNotEqual(actual, actual2) - - def test_rand_mac_address(self): - actual = data_utils.rand_mac_address() - self.assertIsInstance(actual, str) - self.assertRegexpMatches(actual, "^([0-9a-f][0-9a-f]:){5}" - "[0-9a-f][0-9a-f]$") - - actual2 = data_utils.rand_mac_address() - self.assertNotEqual(actual, actual2) - - def test_parse_image_id(self): - actual = data_utils.parse_image_id("/foo/bar/deadbeaf") - self.assertEqual("deadbeaf", actual) - - def test_arbitrary_string(self): - actual = data_utils.arbitrary_string() - self.assertEqual(actual, "test") - actual = data_utils.arbitrary_string(size=30, base_text="abc") - self.assertEqual(actual, "abc" * int(30 / len("abc"))) - actual = data_utils.arbitrary_string(size=5, base_text="deadbeaf") - self.assertEqual(actual, "deadb") - - def test_random_bytes(self): - actual = data_utils.random_bytes() # default size=1024 - self.assertIsInstance(actual, str) - self.assertRegexpMatches(actual, "^[\x00-\xFF]{1024}") - actual2 = data_utils.random_bytes() - self.assertNotEqual(actual, actual2) - - actual = data_utils.random_bytes(size=2048) - self.assertRegexpMatches(actual, "^[\x00-\xFF]{2048}") - - def test_get_ipv6_addr_by_EUI64(self): - actual = data_utils.get_ipv6_addr_by_EUI64('2001:db8::', - '00:16:3e:33:44:55') - self.assertIsInstance(actual, netaddr.IPAddress) - self.assertEqual(actual, - netaddr.IPAddress('2001:db8::216:3eff:fe33:4455')) - - def test_get_ipv6_addr_by_EUI64_with_IPv4_prefix(self): - ipv4_prefix = '10.0.8' - mac = '00:16:3e:33:44:55' - self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, - ipv4_prefix, mac) - - def test_get_ipv6_addr_by_EUI64_bad_cidr_type(self): - bad_cidr = 123 - mac = '00:16:3e:33:44:55' - self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, - bad_cidr, mac) - - def test_get_ipv6_addr_by_EUI64_bad_cidr_value(self): - bad_cidr = 'bb' - mac = '00:16:3e:33:44:55' - self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, - bad_cidr, mac) - - def test_get_ipv6_addr_by_EUI64_bad_mac_value(self): - cidr = '2001:db8::' - bad_mac = '00:16:3e:33:44:5Z' - self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, - cidr, bad_mac) - - def test_get_ipv6_addr_by_EUI64_bad_mac_type(self): - cidr = '2001:db8::' - bad_mac = 99999999999999999999 - self.assertRaises(TypeError, data_utils.get_ipv6_addr_by_EUI64, - cidr, bad_mac) diff --git a/tempest_lib/tests/common/utils/test_misc.py b/tempest_lib/tests/common/utils/test_misc.py deleted file mode 100644 index aefaeef..0000000 --- a/tempest_lib/tests/common/utils/test_misc.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2014 NEC Corporation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -from tempest_lib.common.utils import misc -from tempest_lib.tests import base - - -@misc.singleton -class TestFoo(object): - - count = 0 - - def increment(self): - self.count += 1 - return self.count - - -@misc.singleton -class TestBar(object): - - count = 0 - - def increment(self): - self.count += 1 - return self.count - - -class TestMisc(base.TestCase): - - def test_singleton(self): - test = TestFoo() - self.assertEqual(0, test.count) - self.assertEqual(1, test.increment()) - test2 = TestFoo() - self.assertEqual(1, test.count) - self.assertEqual(1, test2.count) - self.assertEqual(test, test2) - test3 = TestBar() - self.assertNotEqual(test, test3) - - def test_find_test_caller_test_case(self): - # Calling it from here should give us the method we're in. - self.assertEqual('TestMisc:test_find_test_caller_test_case', - misc.find_test_caller()) - - def test_find_test_caller_setup_self(self): - def setUp(self): - return misc.find_test_caller() - self.assertEqual('TestMisc:setUp', setUp(self)) - - def test_find_test_caller_setup_no_self(self): - def setUp(): - return misc.find_test_caller() - self.assertEqual(':setUp', setUp()) - - def test_find_test_caller_setupclass_cls(self): - def setUpClass(cls): # noqa - return misc.find_test_caller() - self.assertEqual('TestMisc:setUpClass', setUpClass(self.__class__)) - - def test_find_test_caller_teardown_self(self): - def tearDown(self): - return misc.find_test_caller() - self.assertEqual('TestMisc:tearDown', tearDown(self)) - - def test_find_test_caller_teardown_no_self(self): - def tearDown(): - return misc.find_test_caller() - self.assertEqual(':tearDown', tearDown()) - - def test_find_test_caller_teardown_class(self): - def tearDownClass(cls): # noqa - return misc.find_test_caller() - self.assertEqual('TestMisc:tearDownClass', - tearDownClass(self.__class__)) diff --git a/tempest_lib/tests/fake_auth_provider.py b/tempest_lib/tests/fake_auth_provider.py deleted file mode 100644 index 280df66..0000000 --- a/tempest_lib/tests/fake_auth_provider.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2014 Hewlett-Packard Development Company, L.P. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - - -class FakeAuthProvider(object): - - def __init__(self, creds_dict={}): - self.credentials = FakeCredentials(creds_dict) - - def auth_request(self, method, url, headers=None, body=None, filters=None): - return url, headers, body - - def base_url(self, filters, auth_data=None): - return "https://example.com" - - -class FakeCredentials(object): - - def __init__(self, creds_dict): - for key in creds_dict.keys(): - setattr(self, key, creds_dict[key]) diff --git a/tempest_lib/tests/fake_credentials.py b/tempest_lib/tests/fake_credentials.py deleted file mode 100644 index 32105a1..0000000 --- a/tempest_lib/tests/fake_credentials.py +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright 2014 Hewlett-Packard Development Company, L.P. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib import auth - - -class FakeCredentials(auth.Credentials): - - def is_valid(self): - return True - - -class FakeKeystoneV2Credentials(auth.KeystoneV2Credentials): - - def __init__(self): - creds = dict( - username='fake_username', - password='fake_password', - tenant_name='fake_tenant_name' - ) - super(FakeKeystoneV2Credentials, self).__init__(**creds) - - -class FakeKeystoneV3Credentials(auth.KeystoneV3Credentials): - """Fake credentials suitable for the Keystone Identity V3 API""" - - def __init__(self): - creds = dict( - username='fake_username', - password='fake_password', - user_domain_name='fake_domain_name', - project_name='fake_tenant_name', - project_domain_name='fake_domain_name' - ) - super(FakeKeystoneV3Credentials, self).__init__(**creds) - - -class FakeKeystoneV3DomainCredentials(auth.KeystoneV3Credentials): - """Fake credentials for the Keystone Identity V3 API, with no scope""" - - def __init__(self): - creds = dict( - username='fake_username', - password='fake_password', - user_domain_name='fake_domain_name' - ) - super(FakeKeystoneV3DomainCredentials, self).__init__(**creds) diff --git a/tempest_lib/tests/fake_http.py b/tempest_lib/tests/fake_http.py deleted file mode 100644 index eda202d..0000000 --- a/tempest_lib/tests/fake_http.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2013 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -import httplib2 - - -class fake_httplib2(object): - - def __init__(self, return_type=None, *args, **kwargs): - self.return_type = return_type - - def request(self, uri, method="GET", body=None, headers=None, - redirections=5, connection_type=None): - if not self.return_type: - fake_headers = httplib2.Response(headers) - return_obj = { - 'uri': uri, - 'method': method, - 'body': body, - 'headers': headers - } - return (fake_headers, return_obj) - elif isinstance(self.return_type, int): - body = body or "fake_body" - header_info = { - 'content-type': 'text/plain', - 'status': str(self.return_type), - 'content-length': len(body) - } - resp_header = httplib2.Response(header_info) - return (resp_header, body) - else: - msg = "unsupported return type %s" % self.return_type - raise TypeError(msg) - - -class fake_httplib(object): - def __init__(self, headers, body=None, - version=1.0, status=200, reason="Ok"): - """Fake httplib implementation - - :param headers: dict representing HTTP response headers - :param body: file-like object - :param version: HTTP Version - :param status: Response status code - :param reason: Status code related message. - """ - self.body = body - self.status = status - self.reason = reason - self.version = version - self.headers = headers - - def getheaders(self): - return copy.deepcopy(self.headers).items() - - def getheader(self, key, default): - return self.headers.get(key, default) - - def read(self, amt): - return self.body.read(amt) diff --git a/tempest_lib/tests/fake_identity.py b/tempest_lib/tests/fake_identity.py deleted file mode 100644 index bac2676..0000000 --- a/tempest_lib/tests/fake_identity.py +++ /dev/null @@ -1,164 +0,0 @@ -# Copyright 2014 IBM Corp. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import json - -import httplib2 - -FAKE_AUTH_URL = 'http://fake_uri.com/auth' - -TOKEN = "fake_token" -ALT_TOKEN = "alt_fake_token" - -# Fake Identity v2 constants -COMPUTE_ENDPOINTS_V2 = { - "endpoints": [ - { - "adminURL": "http://fake_url/v2/first_endpoint/admin", - "region": "NoMatchRegion", - "internalURL": "http://fake_url/v2/first_endpoint/internal", - "publicURL": "http://fake_url/v2/first_endpoint/public" - }, - { - "adminURL": "http://fake_url/v2/second_endpoint/admin", - "region": "FakeRegion", - "internalURL": "http://fake_url/v2/second_endpoint/internal", - "publicURL": "http://fake_url/v2/second_endpoint/public" - }, - ], - "type": "compute", - "name": "nova" -} - -CATALOG_V2 = [COMPUTE_ENDPOINTS_V2, ] - -ALT_IDENTITY_V2_RESPONSE = { - "access": { - "token": { - "expires": "2020-01-01T00:00:10Z", - "id": ALT_TOKEN, - "tenant": { - "id": "fake_alt_tenant_id" - }, - }, - "user": { - "id": "fake_alt_user_id", - }, - "serviceCatalog": CATALOG_V2, - }, -} - -IDENTITY_V2_RESPONSE = { - "access": { - "token": { - "expires": "2020-01-01T00:00:10Z", - "id": TOKEN, - "tenant": { - "id": "fake_tenant_id" - }, - }, - "user": { - "id": "fake_user_id", - }, - "serviceCatalog": CATALOG_V2, - }, -} - -# Fake Identity V3 constants -COMPUTE_ENDPOINTS_V3 = { - "endpoints": [ - { - "id": "first_compute_fake_service", - "interface": "public", - "region": "NoMatchRegion", - "url": "http://fake_url/v3/first_endpoint/api" - }, - { - "id": "second_fake_service", - "interface": "public", - "region": "FakeRegion", - "url": "http://fake_url/v3/second_endpoint/api" - }, - { - "id": "third_fake_service", - "interface": "admin", - "region": "MiddleEarthRegion", - "url": "http://fake_url/v3/third_endpoint/api" - } - - ], - "type": "compute", - "id": "fake_compute_endpoint" -} - -CATALOG_V3 = [COMPUTE_ENDPOINTS_V3, ] - -IDENTITY_V3_RESPONSE = { - "token": { - "methods": [ - "token", - "password" - ], - "expires_at": "2020-01-01T00:00:10.000123Z", - "project": { - "domain": { - "id": "fake_domain_id", - "name": "fake" - }, - "id": "project_id", - "name": "project_name" - }, - "user": { - "domain": { - "id": "fake_domain_id", - "name": "domain_name" - }, - "id": "fake_user_id", - "name": "username" - }, - "issued_at": "2013-05-29T16:55:21.468960Z", - "catalog": CATALOG_V3 - } -} - -ALT_IDENTITY_V3 = IDENTITY_V3_RESPONSE - - -def _fake_v3_response(self, uri, method="GET", body=None, headers=None, - redirections=5, connection_type=None): - fake_headers = { - "status": "201", - "x-subject-token": TOKEN - } - return (httplib2.Response(fake_headers), - json.dumps(IDENTITY_V3_RESPONSE)) - - -def _fake_v2_response(self, uri, method="GET", body=None, headers=None, - redirections=5, connection_type=None): - return (httplib2.Response({"status": "200"}), - json.dumps(IDENTITY_V2_RESPONSE)) - - -def _fake_auth_failure_response(): - # the response body isn't really used in this case, but lets send it anyway - # to have a safe check in some future change on the rest client. - body = { - "unauthorized": { - "message": "Unauthorized", - "code": "401" - } - } - return httplib2.Response({"status": "401"}), json.dumps(body) diff --git a/tempest_lib/tests/services/__init__.py b/tempest_lib/tests/services/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/services/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/services/compute/__init__.py b/tempest_lib/tests/services/compute/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/services/compute/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/services/compute/base.py b/tempest_lib/tests/services/compute/base.py deleted file mode 100644 index 3e4a200..0000000 --- a/tempest_lib/tests/services/compute/base.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright 2015 Deutsche Telekom AG. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import httplib2 -from oslo_serialization import jsonutils as json -from oslotest import mockpatch - -from tempest_lib.tests import base - - -class BaseComputeServiceTest(base.TestCase): - def create_response(self, body, to_utf=False, status=200, headers=None): - json_body = {} - if body: - json_body = json.dumps(body) - if to_utf: - json_body = json_body.encode('utf-8') - resp_dict = {'status': status} - if headers: - resp_dict.update(headers) - response = (httplib2.Response(resp_dict), json_body) - return response - - def check_service_client_function(self, function, function2mock, - body, to_utf=False, status=200, - headers=None, **kwargs): - mocked_response = self.create_response(body, to_utf, status, headers) - self.useFixture(mockpatch.Patch( - function2mock, return_value=mocked_response)) - if kwargs: - resp = function(**kwargs) - else: - resp = function() - self.assertEqual(body, resp) diff --git a/tempest_lib/tests/services/compute/test_agents_client.py b/tempest_lib/tests/services/compute/test_agents_client.py deleted file mode 100644 index 5a480c4..0000000 --- a/tempest_lib/tests/services/compute/test_agents_client.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import agents_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestAgentsClient(base.BaseComputeServiceTest): - FAKE_CREATE_AGENT = { - "agent": { - "url": "http://foo.com", - "hypervisor": "kvm", - "md5hash": "md5", - "version": "2", - "architecture": "x86_64", - "os": "linux", - "agent_id": 1 - } - } - - FAKE_UPDATE_AGENT = { - "agent": { - "url": "http://foo.com", - "md5hash": "md5", - "version": "2", - "agent_id": 1 - } - } - - def setUp(self): - super(TestAgentsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = agents_client.AgentsClient(fake_auth, - 'compute', 'regionOne') - - def _test_list_agents(self, bytes_body=False): - self.check_service_client_function( - self.client.list_agents, - 'tempest_lib.common.rest_client.RestClient.get', - {"agents": []}, - bytes_body) - self.check_service_client_function( - self.client.list_agents, - 'tempest_lib.common.rest_client.RestClient.get', - {"agents": []}, - bytes_body, - hypervisor="kvm") - - def _test_create_agent(self, bytes_body=False): - self.check_service_client_function( - self.client.create_agent, - 'tempest_lib.common.rest_client.RestClient.post', - self.FAKE_CREATE_AGENT, - bytes_body, - url="http://foo.com", hypervisor="kvm", md5hash="md5", - version="2", architecture="x86_64", os="linux") - - def _test_delete_agent(self): - self.check_service_client_function( - self.client.delete_agent, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, agent_id="1") - - def _test_update_agent(self, bytes_body=False): - self.check_service_client_function( - self.client.update_agent, - 'tempest_lib.common.rest_client.RestClient.put', - self.FAKE_UPDATE_AGENT, - bytes_body, - agent_id="1", url="http://foo.com", md5hash="md5", version="2") - - def test_list_agents_with_str_body(self): - self._test_list_agents() - - def test_list_agents_with_bytes_body(self): - self._test_list_agents(bytes_body=True) - - def test_create_agent_with_str_body(self): - self._test_create_agent() - - def test_create_agent_with_bytes_body(self): - self._test_create_agent(bytes_body=True) - - def test_delete_agent(self): - self._test_delete_agent() - - def test_update_agent_with_str_body(self): - self._test_update_agent() - - def test_update_agent_with_bytes_body(self): - self._test_update_agent(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_aggregates_client.py b/tempest_lib/tests/services/compute/test_aggregates_client.py deleted file mode 100644 index b63ed72..0000000 --- a/tempest_lib/tests/services/compute/test_aggregates_client.py +++ /dev/null @@ -1,192 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import aggregates_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestAggregatesClient(base.BaseComputeServiceTest): - FAKE_SHOW_AGGREGATE = { - "aggregate": - { - "name": "hoge", - "availability_zone": None, - "deleted": False, - "created_at": - "2015-07-16T03:07:32.000000", - "updated_at": None, - "hosts": [], - "deleted_at": None, - "id": 1, - "metadata": {} - } - } - - FAKE_CREATE_AGGREGATE = { - "aggregate": - { - "name": u'\xf4', - "availability_zone": None, - "deleted": False, - "created_at": "2015-07-21T04:11:18.000000", - "updated_at": None, - "deleted_at": None, - "id": 1 - } - } - - FAKE_UPDATE_AGGREGATE = { - "aggregate": - { - "name": u'\xe9', - "availability_zone": None, - "deleted": False, - "created_at": "2015-07-16T03:07:32.000000", - "updated_at": "2015-07-23T05:16:29.000000", - "hosts": [], - "deleted_at": None, - "id": 1, - "metadata": {} - } - } - - FAKE_AGGREGATE = { - "availability_zone": "nova", - "created_at": "2013-08-18T12:17:56.297823", - "deleted": False, - "deleted_at": None, - "hosts": [ - "21549b2f665945baaa7101926a00143c" - ], - "id": 1, - "metadata": { - "availability_zone": "nova" - }, - "name": u'\xe9', - "updated_at": None - } - - FAKE_ADD_HOST = {'aggregate': FAKE_AGGREGATE} - FAKE_REMOVE_HOST = {'aggregate': FAKE_AGGREGATE} - FAKE_SET_METADATA = {'aggregate': FAKE_AGGREGATE} - - def setUp(self): - super(TestAggregatesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = aggregates_client.AggregatesClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_aggregates(self, bytes_body=False): - self.check_service_client_function( - self.client.list_aggregates, - 'tempest_lib.common.rest_client.RestClient.get', - {"aggregates": []}, - bytes_body) - - def test_list_aggregates_with_str_body(self): - self._test_list_aggregates() - - def test_list_aggregates_with_bytes_body(self): - self._test_list_aggregates(bytes_body=True) - - def _test_show_aggregate(self, bytes_body=False): - self.check_service_client_function( - self.client.show_aggregate, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_SHOW_AGGREGATE, - bytes_body, - aggregate_id=1) - - def test_show_aggregate_with_str_body(self): - self._test_show_aggregate() - - def test_show_aggregate_with_bytes_body(self): - self._test_show_aggregate(bytes_body=True) - - def _test_create_aggregate(self, bytes_body=False): - self.check_service_client_function( - self.client.create_aggregate, - 'tempest_lib.common.rest_client.RestClient.post', - self.FAKE_CREATE_AGGREGATE, - bytes_body, - name='hoge') - - def test_create_aggregate_with_str_body(self): - self._test_create_aggregate() - - def test_create_aggregate_with_bytes_body(self): - self._test_create_aggregate(bytes_body=True) - - def test_delete_aggregate(self): - self.check_service_client_function( - self.client.delete_aggregate, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, aggregate_id="1") - - def _test_update_aggregate(self, bytes_body=False): - self.check_service_client_function( - self.client.update_aggregate, - 'tempest_lib.common.rest_client.RestClient.put', - self.FAKE_UPDATE_AGGREGATE, - bytes_body, - aggregate_id=1) - - def test_update_aggregate_with_str_body(self): - self._test_update_aggregate() - - def test_update_aggregate_with_bytes_body(self): - self._test_update_aggregate(bytes_body=True) - - def _test_add_host(self, bytes_body=False): - self.check_service_client_function( - self.client.add_host, - 'tempest_lib.common.rest_client.RestClient.post', - self.FAKE_ADD_HOST, - bytes_body, - aggregate_id=1) - - def test_add_host_with_str_body(self): - self._test_add_host() - - def test_add_host_with_bytes_body(self): - self._test_add_host(bytes_body=True) - - def _test_remove_host(self, bytes_body=False): - self.check_service_client_function( - self.client.remove_host, - 'tempest_lib.common.rest_client.RestClient.post', - self.FAKE_REMOVE_HOST, - bytes_body, - aggregate_id=1) - - def test_remove_host_with_str_body(self): - self._test_remove_host() - - def test_remove_host_with_bytes_body(self): - self._test_remove_host(bytes_body=True) - - def _test_set_metadata(self, bytes_body=False): - self.check_service_client_function( - self.client.set_metadata, - 'tempest_lib.common.rest_client.RestClient.post', - self.FAKE_SET_METADATA, - bytes_body, - aggregate_id=1) - - def test_set_metadata_with_str_body(self): - self._test_set_metadata() - - def test_set_metadata_with_bytes_body(self): - self._test_set_metadata(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_availability_zone_client.py b/tempest_lib/tests/services/compute/test_availability_zone_client.py deleted file mode 100644 index 0a97bbf..0000000 --- a/tempest_lib/tests/services/compute/test_availability_zone_client.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import availability_zone_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestAvailabilityZoneClient(base.BaseComputeServiceTest): - - FAKE_AVAILABIRITY_ZONE_INFO = { - "availabilityZoneInfo": - [ - { - "zoneState": { - "available": True - }, - "hosts": None, - "zoneName": u'\xf4' - } - ] - } - - def setUp(self): - super(TestAvailabilityZoneClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = availability_zone_client.AvailabilityZoneClient( - fake_auth, 'compute', 'regionOne') - - def test_list_availability_zones_with_str_body(self): - self.check_service_client_function( - self.client.list_availability_zones, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_AVAILABIRITY_ZONE_INFO) - - def test_list_availability_zones_with_bytes_body(self): - self.check_service_client_function( - self.client.list_availability_zones, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_AVAILABIRITY_ZONE_INFO, to_utf=True) diff --git a/tempest_lib/tests/services/compute/test_baremetal_nodes_client.py b/tempest_lib/tests/services/compute/test_baremetal_nodes_client.py deleted file mode 100644 index 0844fef..0000000 --- a/tempest_lib/tests/services/compute/test_baremetal_nodes_client.py +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from tempest_lib.services.compute import baremetal_nodes_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestBareMetalNodesClient(base.BaseComputeServiceTest): - - FAKE_NODE_INFO = {'cpus': '8', - 'disk_gb': '64', - 'host': '10.0.2.15', - 'id': 'Identifier', - 'instance_uuid': "null", - 'interfaces': [ - { - "address": "20::01", - "datapath_id": "null", - "id": 1, - "port_no": None - } - ], - 'memory_mb': '8192', - 'task_state': None} - - def setUp(self): - super(TestBareMetalNodesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.baremetal_nodes_client = (baremetal_nodes_client. - BaremetalNodesClient - (fake_auth, 'compute', - 'regionOne')) - - def _test_bareMetal_nodes(self, operation='list', bytes_body=False): - if operation != 'list': - expected = {"node": self.FAKE_NODE_INFO} - function = self.baremetal_nodes_client.show_baremetal_node - else: - node_info = copy.deepcopy(self.FAKE_NODE_INFO) - del node_info['instance_uuid'] - expected = {"nodes": [node_info]} - function = self.baremetal_nodes_client.list_baremetal_nodes - - self.check_service_client_function( - function, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body, 200, - baremetal_node_id='Identifier') - - def test_list_bareMetal_nodes_with_str_body(self): - self._test_bareMetal_nodes() - - def test_list_bareMetal_nodes_with_bytes_body(self): - self._test_bareMetal_nodes(bytes_body=True) - - def test_show_bareMetal_node_with_str_body(self): - self._test_bareMetal_nodes('show') - - def test_show_bareMetal_node_with_bytes_body(self): - self._test_bareMetal_nodes('show', True) diff --git a/tempest_lib/tests/services/compute/test_certificates_client.py b/tempest_lib/tests/services/compute/test_certificates_client.py deleted file mode 100644 index 9d5e50a..0000000 --- a/tempest_lib/tests/services/compute/test_certificates_client.py +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from tempest_lib.services.compute import certificates_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestCertificatesClient(base.BaseComputeServiceTest): - - FAKE_CERTIFICATE = { - "certificate": { - "data": "-----BEGIN----MIICyzCCAjSgAwI----END CERTIFICATE-----\n", - "private_key": None - } - } - - def setUp(self): - super(TestCertificatesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = certificates_client.CertificatesClient( - fake_auth, 'compute', 'regionOne') - - def _test_show_certificate(self, bytes_body=False): - self.check_service_client_function( - self.client.show_certificate, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_CERTIFICATE, - bytes_body, - certificate_id="fake-id") - - def test_show_certificate_with_str_body(self): - self._test_show_certificate() - - def test_show_certificate_with_bytes_body(self): - self._test_show_certificate(bytes_body=True) - - def _test_create_certificate(self, bytes_body=False): - cert = copy.deepcopy(self.FAKE_CERTIFICATE) - cert['certificate']['private_key'] = "my_private_key" - self.check_service_client_function( - self.client.create_certificate, - 'tempest_lib.common.rest_client.RestClient.post', - cert, - bytes_body) - - def test_create_certificate_with_str_body(self): - self._test_create_certificate() - - def test_create_certificate_with_bytes_body(self): - self._test_create_certificate(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_extensions_client.py b/tempest_lib/tests/services/compute/test_extensions_client.py deleted file mode 100644 index 084300f..0000000 --- a/tempest_lib/tests/services/compute/test_extensions_client.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import extensions_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestExtensionsClient(base.BaseComputeServiceTest): - - FAKE_SHOW_EXTENSION = { - "extension": { - "updated": "2011-06-09T00:00:00Z", - "name": "Multinic", - "links": [], - "namespace": - "http://docs.openstack.org/compute/ext/multinic/api/v1.1", - "alias": "NMN", - "description": u'\u2740(*\xb4\u25e1`*)\u2740' - } - } - - def setUp(self): - super(TestExtensionsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = extensions_client.ExtensionsClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_extensions(self, bytes_body=False): - self.check_service_client_function( - self.client.list_extensions, - 'tempest_lib.common.rest_client.RestClient.get', - {"extensions": []}, - bytes_body) - - def test_list_extensions_with_str_body(self): - self._test_list_extensions() - - def test_list_extensions_with_bytes_body(self): - self._test_list_extensions(bytes_body=True) - - def _test_show_extension(self, bytes_body=False): - self.check_service_client_function( - self.client.show_extension, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_SHOW_EXTENSION, - bytes_body, - extension_alias="NMN") - - def test_show_extension_with_str_body(self): - self._test_show_extension() - - def test_show_extension_with_bytes_body(self): - self._test_show_extension(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_fixedIPs_client.py b/tempest_lib/tests/services/compute/test_fixedIPs_client.py deleted file mode 100644 index efa4e22..0000000 --- a/tempest_lib/tests/services/compute/test_fixedIPs_client.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import fixed_ips_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestFixedIPsClient(base.BaseComputeServiceTest): - FIXED_IP_INFO = {"fixed_ip": {"address": "10.0.0.1", - "cidr": "10.11.12.0/24", - "host": "localhost", - "hostname": "OpenStack"}} - - def setUp(self): - super(TestFixedIPsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.fixedIPsClient = (fixed_ips_client. - FixedIPsClient - (fake_auth, 'compute', - 'regionOne')) - - def _test_show_fixed_ip(self, bytes_body=False): - self.check_service_client_function( - self.fixedIPsClient.show_fixed_ip, - 'tempest_lib.common.rest_client.RestClient.get', - self.FIXED_IP_INFO, bytes_body, - status=200, fixed_ip='Identifier') - - def test_show_fixed_ip_with_str_body(self): - self._test_show_fixed_ip() - - def test_show_fixed_ip_with_bytes_body(self): - self._test_show_fixed_ip(True) - - def _test_reserve_fixed_ip(self, bytes_body=False): - self.check_service_client_function( - self.fixedIPsClient.reserve_fixed_ip, - 'tempest_lib.common.rest_client.RestClient.post', - {}, bytes_body, - status=202, fixed_ip='Identifier') - - def test_reserve_fixed_ip_with_str_body(self): - self._test_reserve_fixed_ip() - - def test_reserve_fixed_ip_with_bytes_body(self): - self._test_reserve_fixed_ip(True) diff --git a/tempest_lib/tests/services/compute/test_flavors_client.py b/tempest_lib/tests/services/compute/test_flavors_client.py deleted file mode 100644 index a6cec39..0000000 --- a/tempest_lib/tests/services/compute/test_flavors_client.py +++ /dev/null @@ -1,255 +0,0 @@ -# Copyright 2015 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy -import httplib2 - -from oslo_serialization import jsonutils as json -from oslotest import mockpatch - -from tempest_lib.services.compute import flavors_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestFlavorsClient(base.BaseComputeServiceTest): - - FAKE_FLAVOR = { - "disk": 1, - "id": "1", - "links": [{ - "href": "http://openstack.example.com/v2/openstack/flavors/1", - "rel": "self"}, { - "href": "http://openstack.example.com/openstack/flavors/1", - "rel": "bookmark"}], - "name": "m1.tiny", - "ram": 512, - "swap": 1, - "vcpus": 1 - } - - EXTRA_SPECS = {"extra_specs": { - "key1": "value1", - "key2": "value2"} - } - - FAKE_FLAVOR_ACCESS = { - "flavor_id": "10", - "tenant_id": "1a951d988e264818afe520e78697dcbf" - } - - def setUp(self): - super(TestFlavorsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = flavors_client.FlavorsClient(fake_auth, - 'compute', 'regionOne') - - def _test_list_flavors(self, bytes_body=False): - flavor = copy.deepcopy(TestFlavorsClient.FAKE_FLAVOR) - # Remove extra attributes - for attribute in ('disk', 'vcpus', 'ram', 'swap'): - del flavor[attribute] - expected = {'flavors': [flavor]} - self.check_service_client_function( - self.client.list_flavors, - 'tempest_lib.common.rest_client.RestClient.get', - expected, - bytes_body) - - def test_list_flavors_str_body(self): - self._test_list_flavors(bytes_body=False) - - def test_list_flavors_byte_body(self): - self._test_list_flavors(bytes_body=True) - - def _test_show_flavor(self, bytes_body=False): - expected = {"flavor": TestFlavorsClient.FAKE_FLAVOR} - self.check_service_client_function( - self.client.show_flavor, - 'tempest_lib.common.rest_client.RestClient.get', - expected, - bytes_body, - flavor_id='fake-id') - - def test_show_flavor_str_body(self): - self._test_show_flavor(bytes_body=False) - - def test_show_flavor_byte_body(self): - self._test_show_flavor(bytes_body=True) - - def _test_create_flavor(self, bytes_body=False): - expected = {"flavor": TestFlavorsClient.FAKE_FLAVOR} - request = copy.deepcopy(TestFlavorsClient.FAKE_FLAVOR) - # The 'links' parameter should not be passed in - del request['links'] - self.check_service_client_function( - self.client.create_flavor, - 'tempest_lib.common.rest_client.RestClient.post', - expected, - bytes_body, - **request) - - def test_create_flavor_str_body(self): - self._test_create_flavor(bytes_body=False) - - def test_create_flavor__byte_body(self): - self._test_create_flavor(bytes_body=True) - - def test_delete_flavor(self): - self.check_service_client_function( - self.client.delete_flavor, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=202, flavor_id='c782b7a9-33cd-45f0-b795-7f87f456408b') - - def _test_is_resource_deleted(self, flavor_id, is_deleted=True, - bytes_body=False): - body = json.dumps({'flavors': [TestFlavorsClient.FAKE_FLAVOR]}) - if bytes_body: - body = body.encode('utf-8') - response = (httplib2.Response({'status': 200}), body) - self.useFixture(mockpatch.Patch( - 'tempest_lib.common.rest_client.RestClient.get', - return_value=response)) - self.assertEqual(is_deleted, - self.client.is_resource_deleted(flavor_id)) - - def test_is_resource_deleted_true_str_body(self): - self._test_is_resource_deleted('2', bytes_body=False) - - def test_is_resource_deleted_true_byte_body(self): - self._test_is_resource_deleted('2', bytes_body=True) - - def test_is_resource_deleted_false_str_body(self): - self._test_is_resource_deleted('1', is_deleted=False, bytes_body=False) - - def test_is_resource_deleted_false_byte_body(self): - self._test_is_resource_deleted('1', is_deleted=False, bytes_body=True) - - def _test_set_flavor_extra_spec(self, bytes_body=False): - self.check_service_client_function( - self.client.set_flavor_extra_spec, - 'tempest_lib.common.rest_client.RestClient.post', - TestFlavorsClient.EXTRA_SPECS, - bytes_body, - flavor_id='8c7aae5a-d315-4216-875b-ed9b6a5bcfc6', - **TestFlavorsClient.EXTRA_SPECS) - - def test_set_flavor_extra_spec_str_body(self): - self._test_set_flavor_extra_spec(bytes_body=False) - - def test_set_flavor_extra_spec_byte_body(self): - self._test_set_flavor_extra_spec(bytes_body=True) - - def _test_list_flavor_extra_specs(self, bytes_body=False): - self.check_service_client_function( - self.client.list_flavor_extra_specs, - 'tempest_lib.common.rest_client.RestClient.get', - TestFlavorsClient.EXTRA_SPECS, - bytes_body, - flavor_id='8c7aae5a-d315-4216-875b-ed9b6a5bcfc6') - - def test_list_flavor_extra_specs_str_body(self): - self._test_list_flavor_extra_specs(bytes_body=False) - - def test_list_flavor_extra_specs__byte_body(self): - self._test_list_flavor_extra_specs(bytes_body=True) - - def _test_show_flavor_extra_spec(self, bytes_body=False): - expected = {"key": "value"} - self.check_service_client_function( - self.client.show_flavor_extra_spec, - 'tempest_lib.common.rest_client.RestClient.get', - expected, - bytes_body, - flavor_id='8c7aae5a-d315-4216-875b-ed9b6a5bcfc6', - key='key') - - def test_show_flavor_extra_spec_str_body(self): - self._test_show_flavor_extra_spec(bytes_body=False) - - def test_show_flavor_extra_spec__byte_body(self): - self._test_show_flavor_extra_spec(bytes_body=True) - - def _test_update_flavor_extra_spec(self, bytes_body=False): - expected = {"key1": "value"} - self.check_service_client_function( - self.client.update_flavor_extra_spec, - 'tempest_lib.common.rest_client.RestClient.put', - expected, - bytes_body, - flavor_id='8c7aae5a-d315-4216-875b-ed9b6a5bcfc6', - key='key1', **expected) - - def test_update_flavor_extra_spec_str_body(self): - self._test_update_flavor_extra_spec(bytes_body=False) - - def test_update_flavor_extra_spec_byte_body(self): - self._test_update_flavor_extra_spec(bytes_body=True) - - def test_unset_flavor_extra_spec(self): - self.check_service_client_function( - self.client.unset_flavor_extra_spec, - 'tempest_lib.common.rest_client.RestClient.delete', {}, - flavor_id='c782b7a9-33cd-45f0-b795-7f87f456408b', key='key') - - def _test_list_flavor_access(self, bytes_body=False): - expected = {'flavor_access': [TestFlavorsClient.FAKE_FLAVOR_ACCESS]} - self.check_service_client_function( - self.client.list_flavor_access, - 'tempest_lib.common.rest_client.RestClient.get', - expected, - bytes_body, - flavor_id='8c7aae5a-d315-4216-875b-ed9b6a5bcfc6') - - def test_list_flavor_access_str_body(self): - self._test_list_flavor_access(bytes_body=False) - - def test_list_flavor_access_byte_body(self): - self._test_list_flavor_access(bytes_body=True) - - def _test_add_flavor_access(self, bytes_body=False): - expected = { - "flavor_access": [TestFlavorsClient.FAKE_FLAVOR_ACCESS] - } - self.check_service_client_function( - self.client.add_flavor_access, - 'tempest_lib.common.rest_client.RestClient.post', - expected, - bytes_body, - flavor_id='8c7aae5a-d315-4216-875b-ed9b6a5bcfc6', - tenant_id='1a951d988e264818afe520e78697dcbf') - - def test_add_flavor_access_str_body(self): - self._test_add_flavor_access(bytes_body=False) - - def test_add_flavor_access_byte_body(self): - self._test_add_flavor_access(bytes_body=True) - - def _test_remove_flavor_access(self, bytes_body=False): - expected = { - "flavor_access": [TestFlavorsClient.FAKE_FLAVOR_ACCESS] - } - self.check_service_client_function( - self.client.remove_flavor_access, - 'tempest_lib.common.rest_client.RestClient.post', - expected, - bytes_body, - flavor_id='10', - tenant_id='a6edd4d66ad04245b5d2d8716ecc91e3') - - def test_remove_flavor_access_str_body(self): - self._test_remove_flavor_access(bytes_body=False) - - def test_remove_flavor_access_byte_body(self): - self._test_remove_flavor_access(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_floating_ip_pools_client.py b/tempest_lib/tests/services/compute/test_floating_ip_pools_client.py deleted file mode 100644 index 21f9c46..0000000 --- a/tempest_lib/tests/services/compute/test_floating_ip_pools_client.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import floating_ip_pools_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestFloatingIPPoolsClient(base.BaseComputeServiceTest): - - FAKE_FLOATING_IP_POOLS = { - "floating_ip_pools": - [ - {"name": u'\u3042'}, - {"name": u'\u3044'} - ] - } - - def setUp(self): - super(TestFloatingIPPoolsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = floating_ip_pools_client.FloatingIPPoolsClient( - fake_auth, 'compute', 'regionOne') - - def test_list_floating_ip_pools_with_str_body(self): - self.check_service_client_function( - self.client.list_floating_ip_pools, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_FLOATING_IP_POOLS) - - def test_list_floating_ip_pools_with_bytes_body(self): - self.check_service_client_function( - self.client.list_floating_ip_pools, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_FLOATING_IP_POOLS, to_utf=True) diff --git a/tempest_lib/tests/services/compute/test_floating_ips_bulk_client.py b/tempest_lib/tests/services/compute/test_floating_ips_bulk_client.py deleted file mode 100644 index 6926c35..0000000 --- a/tempest_lib/tests/services/compute/test_floating_ips_bulk_client.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.tests import fake_auth_provider - -from tempest_lib.services.compute import floating_ips_bulk_client -from tempest_lib.tests.services.compute import base - - -class TestFloatingIPsBulkClient(base.BaseComputeServiceTest): - - FAKE_FIP_BULK_LIST = {"floating_ip_info": [{ - "address": "10.10.10.1", - "instance_uuid": None, - "fixed_ip": None, - "interface": "eth0", - "pool": "nova", - "project_id": None - }, - { - "address": "10.10.10.2", - "instance_uuid": None, - "fixed_ip": None, - "interface": "eth0", - "pool": "nova", - "project_id": None - }]} - - def setUp(self): - super(TestFloatingIPsBulkClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = floating_ips_bulk_client.FloatingIPsBulkClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_floating_ips_bulk(self, bytes_body=False): - self.check_service_client_function( - self.client.list_floating_ips_bulk, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_FIP_BULK_LIST, - to_utf=bytes_body) - - def _test_create_floating_ips_bulk(self, bytes_body=False): - fake_fip_create_data = {"floating_ips_bulk_create": { - "ip_range": "192.168.1.0/24", "pool": "nova", "interface": "eth0"}} - self.check_service_client_function( - self.client.create_floating_ips_bulk, - 'tempest_lib.common.rest_client.RestClient.post', - fake_fip_create_data, - to_utf=bytes_body, - ip_range="192.168.1.0/24", pool="nova", interface="eth0") - - def _test_delete_floating_ips_bulk(self, bytes_body=False): - fake_fip_delete_data = {"floating_ips_bulk_delete": "192.168.1.0/24"} - self.check_service_client_function( - self.client.delete_floating_ips_bulk, - 'tempest_lib.common.rest_client.RestClient.put', - fake_fip_delete_data, - to_utf=bytes_body, - ip_range="192.168.1.0/24") - - def test_list_floating_ips_bulk_with_str_body(self): - self._test_list_floating_ips_bulk() - - def test_list_floating_ips_bulk_with_bytes_body(self): - self._test_list_floating_ips_bulk(True) - - def test_create_floating_ips_bulk_with_str_body(self): - self._test_create_floating_ips_bulk() - - def test_create_floating_ips_bulk_with_bytes_body(self): - self._test_create_floating_ips_bulk(True) - - def test_delete_floating_ips_bulk_with_str_body(self): - self._test_delete_floating_ips_bulk() - - def test_delete_floating_ips_bulk_with_bytes_body(self): - self._test_delete_floating_ips_bulk(True) diff --git a/tempest_lib/tests/services/compute/test_floating_ips_client.py b/tempest_lib/tests/services/compute/test_floating_ips_client.py deleted file mode 100644 index 01796e5..0000000 --- a/tempest_lib/tests/services/compute/test_floating_ips_client.py +++ /dev/null @@ -1,113 +0,0 @@ -# Copyright 2015 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslotest import mockpatch - -from tempest_lib import exceptions as lib_exc -from tempest_lib.services.compute import floating_ips_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestFloatingIpsClient(base.BaseComputeServiceTest): - - floating_ip = {"fixed_ip": None, - "id": "46d61064-13ba-4bf0-9557-69de824c3d6f", - "instance_id": "a1daa443-a6bb-463e-aea2-104b7d912eb8", - "ip": "10.10.10.1", - "pool": "nova"} - - def setUp(self): - super(TestFloatingIpsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = floating_ips_client.FloatingIPsClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_floating_ips(self, bytes_body=False): - expected = {'floating_ips': [TestFloatingIpsClient.floating_ip]} - self.check_service_client_function( - self.client.list_floating_ips, - 'tempest_lib.common.rest_client.RestClient.get', - expected, - bytes_body) - - def test_list_floating_ips_str_body(self): - self._test_list_floating_ips(bytes_body=False) - - def test_list_floating_ips_byte_body(self): - self._test_list_floating_ips(bytes_body=True) - - def _test_show_floating_ip(self, bytes_body=False): - expected = {"floating_ip": TestFloatingIpsClient.floating_ip} - self.check_service_client_function( - self.client.show_floating_ip, - 'tempest_lib.common.rest_client.RestClient.get', - expected, - bytes_body, - floating_ip_id='a1daa443-a6bb-463e-aea2-104b7d912eb8') - - def test_show_floating_ip_str_body(self): - self._test_show_floating_ip(bytes_body=False) - - def test_show_floating_ip_byte_body(self): - self._test_show_floating_ip(bytes_body=True) - - def _test_create_floating_ip(self, bytes_body=False): - expected = {"floating_ip": TestFloatingIpsClient.floating_ip} - self.check_service_client_function( - self.client.create_floating_ip, - 'tempest_lib.common.rest_client.RestClient.post', - expected, - bytes_body, - pool_name='nova') - - def test_create_floating_ip_str_body(self): - self._test_create_floating_ip(bytes_body=False) - - def test_create_floating_ip_byte_body(self): - self._test_create_floating_ip(bytes_body=True) - - def test_delete_floating_ip(self): - self.check_service_client_function( - self.client.delete_floating_ip, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=202, floating_ip_id='fake-id') - - def test_associate_floating_ip_to_server(self): - self.check_service_client_function( - self.client.associate_floating_ip_to_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, status=202, floating_ip='10.10.10.1', - server_id='c782b7a9-33cd-45f0-b795-7f87f456408b') - - def test_disassociate_floating_ip_from_server(self): - self.check_service_client_function( - self.client.disassociate_floating_ip_from_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, status=202, floating_ip='10.10.10.1', - server_id='c782b7a9-33cd-45f0-b795-7f87f456408b') - - def test_is_resource_deleted_true(self): - self.useFixture(mockpatch.Patch( - 'tempest_lib.services.compute.floating_ips_client.' - 'FloatingIPsClient.show_floating_ip', - side_effect=lib_exc.NotFound())) - self.assertTrue(self.client.is_resource_deleted('fake-id')) - - def test_is_resource_deleted_false(self): - self.useFixture(mockpatch.Patch( - 'tempest_lib.services.compute.floating_ips_client.' - 'FloatingIPsClient.show_floating_ip', - return_value={"floating_ip": TestFloatingIpsClient.floating_ip})) - self.assertFalse(self.client.is_resource_deleted('fake-id')) diff --git a/tempest_lib/tests/services/compute/test_hosts_client.py b/tempest_lib/tests/services/compute/test_hosts_client.py deleted file mode 100644 index c1e053a..0000000 --- a/tempest_lib/tests/services/compute/test_hosts_client.py +++ /dev/null @@ -1,147 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import hosts_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestHostsClient(base.BaseComputeServiceTest): - FAKE_HOST_DATA = { - "host": { - "resource": { - "cpu": 1, - "disk_gb": 1028, - "host": "c1a7de0ac9d94e4baceae031d05caae3", - "memory_mb": 8192, - "project": "(total)" - } - }, - "hosts": { - "host_name": "c1a7de0ac9d94e4baceae031d05caae3", - "service": "conductor", - "zone": "internal" - }, - "enable_hosts": { - "host": "65c5d5b7e3bd44308e67fc50f362aee6", - "maintenance_mode": "off_maintenance", - "status": "enabled" - } - } - - FAKE_CONTROL_DATA = { - "shutdown": { - "host": "c1a7de0ac9d94e4baceae031d05caae3", - "power_action": "shutdown" - }, - "startup": { - "host": "c1a7de0ac9d94e4baceae031d05caae3", - "power_action": "startup" - }, - "reboot": { - "host": "c1a7de0ac9d94e4baceae031d05caae3", - "power_action": "reboot" - }} - - HOST_DATA = {'host': [FAKE_HOST_DATA['host']]} - HOSTS_DATA = {'hosts': [FAKE_HOST_DATA['hosts']]} - ENABLE_HOST_DATA = FAKE_HOST_DATA['enable_hosts'] - HOST_ID = "c1a7de0ac9d94e4baceae031d05caae3" - TEST_HOST_DATA = { - "status": "enable", - "maintenance_mode": "disable" - } - - def setUp(self): - super(TestHostsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = hosts_client.HostsClient(fake_auth, 'compute', - 'regionOne') - self.params = {'hostname': self.HOST_ID} - self.func2mock = { - 'get': 'tempest_lib.common.rest_client.RestClient.get', - 'put': 'tempest_lib.common.rest_client.RestClient.put'} - - def _test_host_data(self, test_type='list', bytes_body=False): - expected_resp = self.HOST_DATA - if test_type != 'list': - function_call = self.client.show_host - else: - expected_resp = self.HOSTS_DATA - function_call = self.client.list_hosts - self.params = {'host_name': self.HOST_ID} - - self.check_service_client_function( - function_call, self.func2mock['get'], - expected_resp, bytes_body, - 200, **self.params) - - def _test_update_hosts(self, bytes_body=False): - expected_resp = self.ENABLE_HOST_DATA - self.check_service_client_function( - self.client.update_host, self.func2mock['put'], - expected_resp, bytes_body, - 200, **self.params) - - def _test_control_host(self, control_op='reboot', bytes_body=False): - if control_op == 'start': - expected_resp = self.FAKE_CONTROL_DATA['startup'] - function_call = self.client.startup_host - elif control_op == 'stop': - expected_resp = self.FAKE_CONTROL_DATA['shutdown'] - function_call = self.client.shutdown_host - else: - expected_resp = self.FAKE_CONTROL_DATA['reboot'] - function_call = self.client.reboot_host - - self.check_service_client_function( - function_call, self.func2mock['get'], - expected_resp, bytes_body, - 200, **self.params) - - def test_show_host_with_str_body(self): - self._test_host_data('show') - - def test_show_host_with_bytes_body(self): - self._test_host_data('show', True) - - def test_list_host_with_str_body(self): - self._test_host_data() - - def test_list_host_with_bytes_body(self): - self._test_host_data(bytes_body=True) - - def test_start_host_with_str_body(self): - self._test_control_host('start') - - def test_start_host_with_bytes_body(self): - self._test_control_host('start', True) - - def test_stop_host_with_str_body(self): - self._test_control_host('stop') - - def test_stop_host_with_bytes_body(self): - self._test_control_host('stop', True) - - def test_reboot_host_with_str_body(self): - self._test_control_host('reboot') - - def test_reboot_host_with_bytes_body(self): - self._test_control_host('reboot', True) - - def test_update_host_with_str_body(self): - self._test_update_hosts() - - def test_update_host_with_bytes_body(self): - self._test_update_hosts(True) diff --git a/tempest_lib/tests/services/compute/test_hypervisor_client.py b/tempest_lib/tests/services/compute/test_hypervisor_client.py deleted file mode 100644 index 1cb85a9..0000000 --- a/tempest_lib/tests/services/compute/test_hypervisor_client.py +++ /dev/null @@ -1,167 +0,0 @@ -# Copyright 2015 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import hypervisor_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestHypervisorClient(base.BaseComputeServiceTest): - - hypervisor_id = "1" - hypervisor_name = "hyper.hostname.com" - - def setUp(self): - super(TestHypervisorClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = hypervisor_client.HypervisorClient( - fake_auth, 'compute', 'regionOne') - - def test_list_hypervisor_str_body(self): - self._test_list_hypervisor(bytes_body=False) - - def test_list_hypervisor_byte_body(self): - self._test_list_hypervisor(bytes_body=True) - - def _test_list_hypervisor(self, bytes_body=False): - expected = {"hypervisors": [{ - "id": 1, - "hypervisor_hostname": "hypervisor1.hostname.com"}, - { - "id": 2, - "hypervisor_hostname": "hypervisor2.hostname.com"}]} - self.check_service_client_function( - self.client.list_hypervisors, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body) - - def test_show_hypervisor_str_body(self): - self._test_show_hypervisor(bytes_body=False) - - def test_show_hypervisor_byte_body(self): - self._test_show_hypervisor(bytes_body=True) - - def _test_show_hypervisor(self, bytes_body=False): - expected = {"hypervisor": { - "cpu_info": "?", - "current_workload": 0, - "disk_available_least": 1, - "host_ip": "10.10.10.10", - "free_disk_gb": 1028, - "free_ram_mb": 7680, - "hypervisor_hostname": "fake-mini", - "hypervisor_type": "fake", - "hypervisor_version": 1, - "id": 1, - "local_gb": 1028, - "local_gb_used": 0, - "memory_mb": 8192, - "memory_mb_used": 512, - "running_vms": 0, - "service": { - "host": "fake_host", - "id": 2}, - "vcpus": 1, - "vcpus_used": 0}} - self.check_service_client_function( - self.client.show_hypervisor, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body, - hypervisor_id=self.hypervisor_id) - - def test_list_servers_on_hypervisor_str_body(self): - self._test_list_servers_on_hypervisor(bytes_body=False) - - def test_list_servers_on_hypervisor_byte_body(self): - self._test_list_servers_on_hypervisor(bytes_body=True) - - def _test_list_servers_on_hypervisor(self, bytes_body=False): - expected = {"hypervisors": [{ - "id": 1, - "hypervisor_hostname": "hyper.hostname.com", - "servers": [{ - "uuid": "e1ae8fc4-b72d-4c2f-a427-30dd420b6277", - "name": "instance-00000001"}, - { - "uuid": "e1ae8fc4-b72d-4c2f-a427-30dd42066666", - "name": "instance-00000002"} - ]} - ]} - self.check_service_client_function( - self.client.list_servers_on_hypervisor, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body, - hypervisor_name=self.hypervisor_name) - - def test_show_hypervisor_statistics_str_body(self): - self._test_show_hypervisor_statistics(bytes_body=False) - - def test_show_hypervisor_statistics_byte_body(self): - self._test_show_hypervisor_statistics(bytes_body=True) - - def _test_show_hypervisor_statistics(self, bytes_body=False): - expected = { - "hypervisor_statistics": { - "count": 1, - "current_workload": 0, - "disk_available_least": 0, - "free_disk_gb": 1028, - "free_ram_mb": 7680, - "local_gb": 1028, - "local_gb_used": 0, - "memory_mb": 8192, - "memory_mb_used": 512, - "running_vms": 0, - "vcpus": 1, - "vcpus_used": 0}} - self.check_service_client_function( - self.client.show_hypervisor_statistics, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body) - - def test_show_hypervisor_uptime_str_body(self): - self._test_show_hypervisor_uptime(bytes_body=False) - - def test_show_hypervisor_uptime_byte_body(self): - self._test_show_hypervisor_uptime(bytes_body=True) - - def _test_show_hypervisor_uptime(self, bytes_body=False): - expected = { - "hypervisor": { - "hypervisor_hostname": "fake-mini", - "id": 1, - "uptime": (" 08:32:11 up 93 days, 18:25, 12 users, " - " load average: 0.20, 0.12, 0.14") - }} - self.check_service_client_function( - self.client.show_hypervisor_uptime, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body, - hypervisor_id=self.hypervisor_id) - - def test_search_hypervisor_str_body(self): - self._test_search_hypervisor(bytes_body=False) - - def test_search_hypervisor_byte_body(self): - self._test_search_hypervisor(bytes_body=True) - - def _test_search_hypervisor(self, bytes_body=False): - expected = {"hypervisors": [{ - "id": 2, - "hypervisor_hostname": "hyper.hostname.com"}]} - self.check_service_client_function( - self.client.search_hypervisor, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body, - hypervisor_name=self.hypervisor_name) diff --git a/tempest_lib/tests/services/compute/test_images_client.py b/tempest_lib/tests/services/compute/test_images_client.py deleted file mode 100644 index f0079c0..0000000 --- a/tempest_lib/tests/services/compute/test_images_client.py +++ /dev/null @@ -1,265 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from oslotest import mockpatch - -from tempest_lib import exceptions as lib_exc -from tempest_lib.services.compute import images_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestImagesClient(base.BaseComputeServiceTest): - # Data Dictionaries used for testing # - FAKE_IMAGE_METADATA = { - "list": - {"metadata": { - "auto_disk_config": "True", - "Label": "Changed" - }}, - "set_item": - {"meta": { - "auto_disk_config": "True" - }}, - "show_item": - {"meta": { - "kernel_id": "nokernel", - }}, - "update": - {"metadata": { - "kernel_id": "False", - "Label": "UpdatedImage" - }}, - "set": - {"metadata": { - "Label": "Changed", - "auto_disk_config": "True" - }}, - "delete_item": {} - } - - FAKE_IMAGE_DATA = { - "list": - {"images": [ - {"id": "70a599e0-31e7-49b7-b260-868f441e862b", - "links": [ - {"href": "http://openstack.example.com/v2/openstack" + - "/images/70a599e0-31e7-49b7-b260-868f441e862b", - "rel": "self" - } - ], - "name": "fakeimage7" - }]}, - "show": {"image": { - "created": "2011-01-01T01:02:03Z", - "id": "70a599e0-31e7-49b7-b260-868f441e862b", - "links": [ - { - "href": "http://openstack.example.com/v2/openstack" + - "/images/70a599e0-31e7-49b7-b260-868f441e862b", - "rel": "self" - }, - ], - "metadata": { - "architecture": "x86_64", - "auto_disk_config": "True", - "kernel_id": "nokernel", - "ramdisk_id": "nokernel" - }, - "minDisk": 0, - "minRam": 0, - "name": "fakeimage7", - "progress": 100, - "status": "ACTIVE", - "updated": "2011-01-01T01:02:03Z"}}, - "create": {}, - "delete": {} - } - func2mock = { - 'get': 'tempest_lib.common.rest_client.RestClient.get', - 'post': 'tempest_lib.common.rest_client.RestClient.post', - 'put': 'tempest_lib.common.rest_client.RestClient.put', - 'delete': 'tempest_lib.common.rest_client.RestClient.delete'} - # Variable definition - FAKE_IMAGE_ID = FAKE_IMAGE_DATA['show']['image']['id'] - FAKE_SERVER_ID = "80a599e0-31e7-49b7-b260-868f441e343f" - FAKE_CREATE_INFO = {'location': 'None'} - FAKE_METADATA = FAKE_IMAGE_METADATA['show_item']['meta'] - - def setUp(self): - super(TestImagesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = images_client.ImagesClient(fake_auth, - "compute", "regionOne") - - def _test_image_operation(self, operation="delete", bytes_body=False): - response_code = 200 - mock_operation = self.func2mock['get'] - expected_op = self.FAKE_IMAGE_DATA[operation] - params = {"image_id": self.FAKE_IMAGE_ID} - headers = None - if operation == 'list': - function = self.client.list_images - elif operation == 'show': - function = self.client.show_image - elif operation == 'create': - function = self.client.create_image - mock_operation = self.func2mock['post'] - params = {"server_id": self.FAKE_SERVER_ID} - response_code = 202 - headers = { - 'connection': 'keep-alive', - 'content-length': '0', - 'content-type': 'application/json', - 'status': '202', - 'x-compute-request-id': 'req-fake', - 'vary': 'accept-encoding', - 'x-openstack-nova-api-version': 'v2.1', - 'date': '13 Oct 2015 05:55:36 GMT', - 'location': 'http://fake.com/images/fake' - } - else: - function = self.client.delete_image - mock_operation = self.func2mock['delete'] - response_code = 204 - - self.check_service_client_function( - function, mock_operation, expected_op, - bytes_body, response_code, headers, **params) - - def _test_image_metadata(self, operation="set_item", bytes_body=False): - response_code = 200 - expected_op = self.FAKE_IMAGE_METADATA[operation] - if operation == 'list': - function = self.client.list_image_metadata - mock_operation = self.func2mock['get'] - params = {"image_id": self.FAKE_IMAGE_ID} - - elif operation == 'set': - function = self.client.set_image_metadata - mock_operation = self.func2mock['put'] - params = {"image_id": "_dummy_data", - "meta": self.FAKE_METADATA} - - elif operation == 'update': - function = self.client.update_image_metadata - mock_operation = self.func2mock['post'] - params = {"image_id": self.FAKE_IMAGE_ID, - "meta": self.FAKE_METADATA} - - elif operation == 'show_item': - mock_operation = self.func2mock['get'] - function = self.client.show_image_metadata_item - params = {"image_id": self.FAKE_IMAGE_ID, - "key": "123"} - - elif operation == 'delete_item': - function = self.client.delete_image_metadata_item - mock_operation = self.func2mock['delete'] - response_code = 204 - params = {"image_id": self.FAKE_IMAGE_ID, - "key": "123"} - - else: - function = self.client.set_image_metadata_item - mock_operation = self.func2mock['put'] - params = {"image_id": self.FAKE_IMAGE_ID, - "key": "123", - "meta": self.FAKE_METADATA} - - self.check_service_client_function( - function, mock_operation, expected_op, - bytes_body, response_code, **params) - - def _test_resource_deleted(self, bytes_body=False): - params = {"id": self.FAKE_IMAGE_ID} - expected_op = self.FAKE_IMAGE_DATA['show']['image'] - self.useFixture(mockpatch.Patch('tempest_lib.services.compute' - '.images_client.ImagesClient.show_image', - side_effect=lib_exc.NotFound)) - self.assertEqual(True, self.client.is_resource_deleted(**params)) - tempdata = copy.deepcopy(self.FAKE_IMAGE_DATA['show']) - tempdata['image']['id'] = None - self.useFixture(mockpatch.Patch('tempest_lib.services.compute' - '.images_client.ImagesClient.show_image', - return_value=expected_op)) - self.assertEqual(False, self.client.is_resource_deleted(**params)) - - def test_list_images_with_str_body(self): - self._test_image_operation('list') - - def test_list_images_with_bytes_body(self): - self._test_image_operation('list', True) - - def test_show_image_with_str_body(self): - self._test_image_operation('show') - - def test_show_image_with_bytes_body(self): - self._test_image_operation('show', True) - - def test_create_image_with_str_body(self): - self._test_image_operation('create') - - def test_create_image_with_bytes_body(self): - self._test_image_operation('create', True) - - def test_delete_image_with_str_body(self): - self._test_image_operation('delete') - - def test_delete_image_with_bytes_body(self): - self._test_image_operation('delete', True) - - def test_list_image_metadata_with_str_body(self): - self._test_image_metadata('list') - - def test_list_image_metadata_with_bytes_body(self): - self._test_image_metadata('list', True) - - def test_set_image_metadata_with_str_body(self): - self._test_image_metadata('set') - - def test_set_image_metadata_with_bytes_body(self): - self._test_image_metadata('set', True) - - def test_update_image_metadata_with_str_body(self): - self._test_image_metadata('update') - - def test_update_image_metadata_with_bytes_body(self): - self._test_image_metadata('update', True) - - def test_set_image_metadata_item_with_str_body(self): - self._test_image_metadata() - - def test_set_image_metadata_item_with_bytes_body(self): - self._test_image_metadata(bytes_body=True) - - def test_show_image_metadata_item_with_str_body(self): - self._test_image_metadata('show_item') - - def test_show_image_metadata_item_with_bytes_body(self): - self._test_image_metadata('show_item', True) - - def test_delete_image_metadata_item_with_str_body(self): - self._test_image_metadata('delete_item') - - def test_delete_image_metadata_item_with_bytes_body(self): - self._test_image_metadata('delete_item', True) - - def test_resource_delete_with_str_body(self): - self._test_resource_deleted() - - def test_resource_delete_with_bytes_body(self): - self._test_resource_deleted(True) diff --git a/tempest_lib/tests/services/compute/test_instance_usage_audit_log_client.py b/tempest_lib/tests/services/compute/test_instance_usage_audit_log_client.py deleted file mode 100644 index 78ade47..0000000 --- a/tempest_lib/tests/services/compute/test_instance_usage_audit_log_client.py +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import datetime - -from tempest_lib.services.compute import instance_usage_audit_log_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestInstanceUsagesAuditLogClient(base.BaseComputeServiceTest): - - FAKE_AUDIT_LOG = { - "hosts_not_run": [ - "f4eb7cfd155f4574967f8b55a7faed75" - ], - "log": {}, - "num_hosts": 1, - "num_hosts_done": 0, - "num_hosts_not_run": 1, - "num_hosts_running": 0, - "overall_status": "0 of 1 hosts done. 0 errors.", - "period_beginning": "2012-12-01 00:00:00", - "period_ending": "2013-01-01 00:00:00", - "total_errors": 0, - "total_instances": 0 - } - - def setUp(self): - super(TestInstanceUsagesAuditLogClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = (instance_usage_audit_log_client. - InstanceUsagesAuditLogClient(fake_auth, 'compute', - 'regionOne')) - - def _test_list_instance_usage_audit_logs(self, bytes_body=False): - self.check_service_client_function( - self.client.list_instance_usage_audit_logs, - 'tempest_lib.common.rest_client.RestClient.get', - {"instance_usage_audit_logs": self.FAKE_AUDIT_LOG}, - bytes_body) - - def test_list_instance_usage_audit_logs_with_str_body(self): - self._test_list_instance_usage_audit_logs() - - def test_list_instance_usage_audit_logs_with_bytes_body(self): - self._test_list_instance_usage_audit_logs(bytes_body=True) - - def _test_show_instance_usage_audit_log(self, bytes_body=False): - before_time = datetime.datetime(2012, 12, 1, 0, 0) - self.check_service_client_function( - self.client.show_instance_usage_audit_log, - 'tempest_lib.common.rest_client.RestClient.get', - {"instance_usage_audit_log": self.FAKE_AUDIT_LOG}, - bytes_body, - time_before=before_time) - - def test_show_instance_usage_audit_log_with_str_body(self): - self._test_show_instance_usage_audit_log() - - def test_show_network_with_bytes_body_with_bytes_body(self): - self._test_show_instance_usage_audit_log(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_interfaces_client.py b/tempest_lib/tests/services/compute/test_interfaces_client.py deleted file mode 100644 index 4456ce7..0000000 --- a/tempest_lib/tests/services/compute/test_interfaces_client.py +++ /dev/null @@ -1,98 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import interfaces_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestInterfacesClient(base.BaseComputeServiceTest): - # Data Values to be used for testing # - FAKE_INTERFACE_DATA = { - "fixed_ips": [{ - "ip_address": "192.168.1.1", - "subnet_id": "f8a6e8f8-c2ec-497c-9f23-da9616de54ef" - }], - "mac_addr": "fa:16:3e:4c:2c:30", - "net_id": "3cb9bc59-5699-4588-a4b1-b87f96708bc6", - "port_id": "ce531f90-199f-48c0-816c-13e38010b442", - "port_state": "ACTIVE"} - - FAKE_SHOW_DATA = { - "interfaceAttachment": FAKE_INTERFACE_DATA} - FAKE_LIST_DATA = { - "interfaceAttachments": [FAKE_INTERFACE_DATA]} - - FAKE_SERVER_ID = "ec14c864-096e-4e27-bb8a-2c2b4dc6f3f5" - FAKE_PORT_ID = FAKE_SHOW_DATA['interfaceAttachment']['port_id'] - func2mock = { - 'delete': 'tempest_lib.common.rest_client.RestClient.delete', - 'get': 'tempest_lib.common.rest_client.RestClient.get', - 'post': 'tempest_lib.common.rest_client.RestClient.post'} - - def setUp(self): - super(TestInterfacesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = interfaces_client.InterfacesClient(fake_auth, - "compute", - "regionOne") - - def _test_interface_operation(self, operation="create", bytes_body=False): - response_code = 200 - expected_op = self.FAKE_SHOW_DATA - mock_operation = self.func2mock['get'] - params = {'server_id': self.FAKE_SERVER_ID, - 'port_id': self.FAKE_PORT_ID} - if operation == 'list': - expected_op = self.FAKE_LIST_DATA - function = self.client.list_interfaces - params = {'server_id': self.FAKE_SERVER_ID} - elif operation == 'show': - function = self.client.show_interface - elif operation == 'delete': - expected_op = {} - mock_operation = self.func2mock['delete'] - function = self.client.delete_interface - response_code = 202 - else: - function = self.client.create_interface - mock_operation = self.func2mock['post'] - - self.check_service_client_function( - function, mock_operation, expected_op, - bytes_body, response_code, **params) - - def test_list_interfaces_with_str_body(self): - self._test_interface_operation('list') - - def test_list_interfaces_with_bytes_body(self): - self._test_interface_operation('list', True) - - def test_show_interface_with_str_body(self): - self._test_interface_operation('show') - - def test_show_interface_with_bytes_body(self): - self._test_interface_operation('show', True) - - def test_delete_interface_with_str_body(self): - self._test_interface_operation('delete') - - def test_delete_interface_with_bytes_body(self): - self._test_interface_operation('delete', True) - - def test_create_interface_with_str_body(self): - self._test_interface_operation() - - def test_create_interface_with_bytes_body(self): - self._test_interface_operation(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_keypairs_client.py b/tempest_lib/tests/services/compute/test_keypairs_client.py deleted file mode 100644 index 6458e67..0000000 --- a/tempest_lib/tests/services/compute/test_keypairs_client.py +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from tempest_lib.services.compute import keypairs_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestKeyPairsClient(base.BaseComputeServiceTest): - - FAKE_KEYPAIR = {"keypair": { - "public_key": "ssh-rsa foo Generated-by-Nova", - "name": u'\u2740(*\xb4\u25e1`*)\u2740', - "user_id": "525d55f98980415ba98e634972fa4a10", - "fingerprint": "76:24:66:49:d7:ca:6e:5c:77:ea:8e:bb:9c:15:5f:98" - }} - - def setUp(self): - super(TestKeyPairsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = keypairs_client.KeyPairsClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_keypairs(self, bytes_body=False): - self.check_service_client_function( - self.client.list_keypairs, - 'tempest_lib.common.rest_client.RestClient.get', - {"keypairs": []}, - bytes_body) - - def test_list_keypairs_with_str_body(self): - self._test_list_keypairs() - - def test_list_keypairs_with_bytes_body(self): - self._test_list_keypairs(bytes_body=True) - - def _test_show_keypair(self, bytes_body=False): - fake_keypair = copy.deepcopy(self.FAKE_KEYPAIR) - fake_keypair["keypair"].update({ - "deleted": False, - "created_at": "2015-07-22T04:53:52.000000", - "updated_at": None, - "deleted_at": None, - "id": 1 - }) - - self.check_service_client_function( - self.client.show_keypair, - 'tempest_lib.common.rest_client.RestClient.get', - fake_keypair, - bytes_body, - keypair_name="test") - - def test_show_keypair_with_str_body(self): - self._test_show_keypair() - - def test_show_keypair_with_bytes_body(self): - self._test_show_keypair(bytes_body=True) - - def _test_create_keypair(self, bytes_body=False): - fake_keypair = copy.deepcopy(self.FAKE_KEYPAIR) - fake_keypair["keypair"].update({"private_key": "foo"}) - - self.check_service_client_function( - self.client.create_keypair, - 'tempest_lib.common.rest_client.RestClient.post', - fake_keypair, - bytes_body, - name="test") - - def test_create_keypair_with_str_body(self): - self._test_create_keypair() - - def test_create_keypair_with_bytes_body(self): - self._test_create_keypair(bytes_body=True) - - def test_delete_keypair(self): - self.check_service_client_function( - self.client.delete_keypair, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=202, keypair_name='test') diff --git a/tempest_lib/tests/services/compute/test_limits_client.py b/tempest_lib/tests/services/compute/test_limits_client.py deleted file mode 100644 index c84b75e..0000000 --- a/tempest_lib/tests/services/compute/test_limits_client.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import limits_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestLimitsClient(base.BaseComputeServiceTest): - - def setUp(self): - super(TestLimitsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = limits_client.LimitsClient( - fake_auth, 'compute', 'regionOne') - - def _test_show_limits(self, bytes_body=False): - expected = { - "limits": { - "rate": [], - "absolute": { - "maxServerMeta": 128, - "maxPersonality": 5, - "totalServerGroupsUsed": 0, - "maxImageMeta": 128, - "maxPersonalitySize": 10240, - "maxServerGroups": 10, - "maxSecurityGroupRules": 20, - "maxTotalKeypairs": 100, - "totalCoresUsed": 0, - "totalRAMUsed": 0, - "totalInstancesUsed": 0, - "maxSecurityGroups": 10, - "totalFloatingIpsUsed": 0, - "maxTotalCores": 20, - "totalSecurityGroupsUsed": 0, - "maxTotalFloatingIps": 10, - "maxTotalInstances": 10, - "maxTotalRAMSize": 51200, - "maxServerGroupMembers": 10 - } - } - } - - self.check_service_client_function( - self.client.show_limits, - 'tempest_lib.common.rest_client.RestClient.get', - expected, - bytes_body) - - def test_show_limits_with_str_body(self): - self._test_show_limits() - - def test_show_limits_with_bytes_body(self): - self._test_show_limits(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_migrations_client.py b/tempest_lib/tests/services/compute/test_migrations_client.py deleted file mode 100644 index a949d67..0000000 --- a/tempest_lib/tests/services/compute/test_migrations_client.py +++ /dev/null @@ -1,52 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import migrations_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestMigrationsClient(base.BaseComputeServiceTest): - FAKE_MIGRATION_INFO = {"migrations": [{ - "created_at": "2012-10-29T13:42:02", - "dest_compute": "compute2", - "dest_host": "1.2.3.4", - "dest_node": "node2", - "id": 1234, - "instance_uuid": "e9e4fdd7-f956-44ff-bfeb-d654a96ab3a2", - "new_instance_type_id": 2, - "old_instance_type_id": 1, - "source_compute": "compute1", - "source_node": "node1", - "status": "finished", - "updated_at": "2012-10-29T13:42:02"}]} - - def setUp(self): - super(TestMigrationsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.mg_client_obj = migrations_client.MigrationsClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_migrations(self, bytes_body=False): - self.check_service_client_function( - self.mg_client_obj.list_migrations, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_MIGRATION_INFO, - bytes_body) - - def test_list_migration_with_str_body(self): - self._test_list_migrations() - - def test_list_migration_with_bytes_body(self): - self._test_list_migrations(True) diff --git a/tempest_lib/tests/services/compute/test_networks_client.py b/tempest_lib/tests/services/compute/test_networks_client.py deleted file mode 100644 index c3b2a98..0000000 --- a/tempest_lib/tests/services/compute/test_networks_client.py +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import networks_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestNetworksClient(base.BaseComputeServiceTest): - - FAKE_NETWORK = { - "bridge": None, - "vpn_public_port": None, - "dhcp_start": None, - "bridge_interface": None, - "share_address": None, - "updated_at": None, - "id": "34d5ae1e-5659-49cf-af80-73bccd7d7ad3", - "cidr_v6": None, - "deleted_at": None, - "gateway": None, - "rxtx_base": None, - "label": u'30d7', - "priority": None, - "project_id": None, - "vpn_private_address": None, - "deleted": None, - "vlan": None, - "broadcast": None, - "netmask": None, - "injected": None, - "cidr": None, - "vpn_public_address": None, - "multi_host": None, - "enable_dhcp": None, - "dns2": None, - "created_at": None, - "host": None, - "mtu": None, - "gateway_v6": None, - "netmask_v6": None, - "dhcp_server": None, - "dns1": None - } - - network_id = "34d5ae1e-5659-49cf-af80-73bccd7d7ad3" - - FAKE_NETWORKS = [FAKE_NETWORK] - - def setUp(self): - super(TestNetworksClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = networks_client.NetworksClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_networks(self, bytes_body=False): - fake_list = {"networks": self.FAKE_NETWORKS} - self.check_service_client_function( - self.client.list_networks, - 'tempest_lib.common.rest_client.RestClient.get', - fake_list, - bytes_body) - - def test_list_networks_with_str_body(self): - self._test_list_networks() - - def test_list_networks_with_bytes_body(self): - self._test_list_networks(bytes_body=True) - - def _test_show_network(self, bytes_body=False): - self.check_service_client_function( - self.client.show_network, - 'tempest_lib.common.rest_client.RestClient.get', - {"network": self.FAKE_NETWORK}, - bytes_body, - network_id=self.network_id - ) - - def test_show_network_with_str_body(self): - self._test_show_network() - - def test_show_network_with_bytes_body(self): - self._test_show_network(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_quota_classes_client.py b/tempest_lib/tests/services/compute/test_quota_classes_client.py deleted file mode 100644 index 309e026..0000000 --- a/tempest_lib/tests/services/compute/test_quota_classes_client.py +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from tempest_lib.services.compute import quota_classes_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestQuotaClassesClient(base.BaseComputeServiceTest): - - FAKE_QUOTA_CLASS_SET = { - "injected_file_content_bytes": 10240, - "metadata_items": 128, - "server_group_members": 10, - "server_groups": 10, - "ram": 51200, - "floating_ips": 10, - "key_pairs": 100, - "id": u'\u2740(*\xb4\u25e1`*)\u2740', - "instances": 10, - "security_group_rules": 20, - "security_groups": 10, - "injected_files": 5, - "cores": 20, - "fixed_ips": -1, - "injected_file_path_bytes": 255, - } - - def setUp(self): - super(TestQuotaClassesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = quota_classes_client.QuotaClassesClient( - fake_auth, 'compute', 'regionOne') - - def _test_show_quota_class_set(self, bytes_body=False): - fake_body = {'quota_class_set': self.FAKE_QUOTA_CLASS_SET} - self.check_service_client_function( - self.client.show_quota_class_set, - 'tempest_lib.common.rest_client.RestClient.get', - fake_body, - bytes_body, - quota_class_id="test") - - def test_show_quota_class_set_with_str_body(self): - self._test_show_quota_class_set() - - def test_show_quota_class_set_with_bytes_body(self): - self._test_show_quota_class_set(bytes_body=True) - - def test_update_quota_class_set(self): - fake_quota_class_set = copy.deepcopy(self.FAKE_QUOTA_CLASS_SET) - fake_quota_class_set.pop("id") - fake_body = {'quota_class_set': fake_quota_class_set} - self.check_service_client_function( - self.client.update_quota_class_set, - 'tempest_lib.common.rest_client.RestClient.put', - fake_body, - quota_class_id="test") diff --git a/tempest_lib/tests/services/compute/test_quotas_client.py b/tempest_lib/tests/services/compute/test_quotas_client.py deleted file mode 100644 index 9c8fb49..0000000 --- a/tempest_lib/tests/services/compute/test_quotas_client.py +++ /dev/null @@ -1,130 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from tempest_lib.services.compute import quotas_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestQuotasClient(base.BaseComputeServiceTest): - - FAKE_QUOTA_SET = { - "quota_set": { - "injected_file_content_bytes": 10240, - "metadata_items": 128, - "server_group_members": 10, - "server_groups": 10, - "ram": 51200, - "floating_ips": 10, - "key_pairs": 100, - "id": "8421f7be61064f50b680465c07f334af", - "instances": 10, - "security_group_rules": 20, - "injected_files": 5, - "cores": 20, - "fixed_ips": -1, - "injected_file_path_bytes": 255, - "security_groups": 10} - } - - project_id = "8421f7be61064f50b680465c07f334af" - fake_user_id = "65f09168cbb04eb593f3138b63b67b67" - - def setUp(self): - super(TestQuotasClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = quotas_client.QuotasClient( - fake_auth, 'compute', 'regionOne') - - def _test_show_quota_set(self, bytes_body=False, user_id=None): - if user_id: - self.check_service_client_function( - self.client.show_quota_set, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_QUOTA_SET, - to_utf=bytes_body, - tenant_id=self.project_id, - user_id=user_id) - else: - self.check_service_client_function( - self.client.show_quota_set, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_QUOTA_SET, - to_utf=bytes_body, - tenant_id=self.project_id) - - def test_show_quota_set_with_str_body(self): - self._test_show_quota_set() - - def test_show_quota_set_with_bytes_body(self): - self._test_show_quota_set(bytes_body=True) - - def test_show_quota_set_for_user_with_str_body(self): - self._test_show_quota_set(user_id=self.fake_user_id) - - def test_show_quota_set_for_user_with_bytes_body(self): - self._test_show_quota_set(bytes_body=True, user_id=self.fake_user_id) - - def _test_show_default_quota_set(self, bytes_body=False): - self.check_service_client_function( - self.client.show_default_quota_set, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_QUOTA_SET, - to_utf=bytes_body, - tenant_id=self.project_id) - - def test_show_default_quota_set_with_str_body(self): - self._test_show_default_quota_set() - - def test_show_default_quota_set_with_bytes_body(self): - self._test_show_default_quota_set(bytes_body=True) - - def _test_update_quota_set(self, bytes_body=False, user_id=None): - fake_quota_set = copy.deepcopy(self.FAKE_QUOTA_SET) - fake_quota_set['quota_set'].pop("id") - if user_id: - self.check_service_client_function( - self.client.update_quota_set, - 'tempest_lib.common.rest_client.RestClient.put', - fake_quota_set, - to_utf=bytes_body, - tenant_id=self.project_id, - user_id=user_id) - else: - self.check_service_client_function( - self.client.update_quota_set, - 'tempest_lib.common.rest_client.RestClient.put', - fake_quota_set, - to_utf=bytes_body, - tenant_id=self.project_id) - - def test_update_quota_set_with_str_body(self): - self._test_update_quota_set() - - def test_update_quota_set_with_bytes_body(self): - self._test_update_quota_set(bytes_body=True) - - def test_update_quota_set_for_user_with_str_body(self): - self._test_update_quota_set(user_id=self.fake_user_id) - - def test_update_quota_set_for_user_with_bytes_body(self): - self._test_update_quota_set(bytes_body=True, user_id=self.fake_user_id) - - def test_delete_quota_set(self): - self.check_service_client_function( - self.client.delete_quota_set, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=202, tenant_id=self.project_id) diff --git a/tempest_lib/tests/services/compute/test_security_group_default_rules_client.py b/tempest_lib/tests/services/compute/test_security_group_default_rules_client.py deleted file mode 100644 index d8a5f64..0000000 --- a/tempest_lib/tests/services/compute/test_security_group_default_rules_client.py +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import security_group_default_rules_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestSecurityGroupDefaultRulesClient(base.BaseComputeServiceTest): - FAKE_RULE = { - "from_port": 80, - "id": 1, - "ip_protocol": "TCP", - "ip_range": { - "cidr": "10.10.10.0/24" - }, - "to_port": 80 - } - - def setUp(self): - super(TestSecurityGroupDefaultRulesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = (security_group_default_rules_client. - SecurityGroupDefaultRulesClient(fake_auth, 'compute', - 'regionOne')) - - def _test_list_security_group_default_rules(self, bytes_body=False): - self.check_service_client_function( - self.client.list_security_group_default_rules, - 'tempest_lib.common.rest_client.RestClient.get', - {"security_group_default_rules": [self.FAKE_RULE]}, - to_utf=bytes_body) - - def test_list_security_group_default_rules_with_str_body(self): - self._test_list_security_group_default_rules() - - def test_list_security_group_default_rules_with_bytes_body(self): - self._test_list_security_group_default_rules(bytes_body=True) - - def _test_show_security_group_default_rule(self, bytes_body=False): - self.check_service_client_function( - self.client.show_security_group_default_rule, - 'tempest_lib.common.rest_client.RestClient.get', - {"security_group_default_rule": self.FAKE_RULE}, - to_utf=bytes_body, - security_group_default_rule_id=1) - - def test_show_security_group_default_rule_with_str_body(self): - self._test_show_security_group_default_rule() - - def test_show_security_group_default_rule_with_bytes_body(self): - self._test_show_security_group_default_rule(bytes_body=True) - - def _test_create_security_default_group_rule(self, bytes_body=False): - request_body = { - "to_port": 80, - "from_port": 80, - "ip_protocol": "TCP", - "cidr": "10.10.10.0/24" - } - self.check_service_client_function( - self.client.create_security_default_group_rule, - 'tempest_lib.common.rest_client.RestClient.post', - {"security_group_default_rule": self.FAKE_RULE}, - to_utf=bytes_body, **request_body) - - def test_create_security_default_group_rule_with_str_body(self): - self._test_create_security_default_group_rule() - - def test_create_security_default_group_rule_with_bytes_body(self): - self._test_create_security_default_group_rule(bytes_body=True) - - def test_delete_security_group_default_rule(self): - self.check_service_client_function( - self.client.delete_security_group_default_rule, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=204, security_group_default_rule_id=1) diff --git a/tempest_lib/tests/services/compute/test_security_group_rules_client.py b/tempest_lib/tests/services/compute/test_security_group_rules_client.py deleted file mode 100644 index 2ff3229..0000000 --- a/tempest_lib/tests/services/compute/test_security_group_rules_client.py +++ /dev/null @@ -1,66 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import security_group_rules_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestSecurityGroupRulesClient(base.BaseComputeServiceTest): - - FAKE_SECURITY_GROUP_RULE = { - "security_group_rule": { - "id": "2d021cf1-ce4b-4292-994f-7a785d62a144", - "ip_range": { - "cidr": "0.0.0.0/0" - }, - "parent_group_id": "48700ff3-30b8-4e63-845f-a79c9633e9fb", - "to_port": 443, - "ip_protocol": "tcp", - "group": {}, - "from_port": 443 - } - } - - def setUp(self): - super(TestSecurityGroupRulesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = security_group_rules_client.SecurityGroupRulesClient( - fake_auth, 'compute', 'regionOne') - - def _test_create_security_group_rule(self, bytes_body=False): - req_body = { - "from_port": "443", - "ip_protocol": "tcp", - "to_port": "443", - "cidr": "0.0.0.0/0", - "parent_group_id": "48700ff3-30b8-4e63-845f-a79c9633e9fb" - } - self.check_service_client_function( - self.client.create_security_group_rule, - 'tempest_lib.common.rest_client.RestClient.post', - self.FAKE_SECURITY_GROUP_RULE, - to_utf=bytes_body, **req_body) - - def test_create_security_group_rule_with_str_body(self): - self._test_create_security_group_rule() - - def test_create_security_group_rule_with_bytes_body(self): - self._test_create_security_group_rule(bytes_body=True) - - def test_delete_security_group_rule(self): - self.check_service_client_function( - self.client.delete_security_group_rule, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=202, group_rule_id='group-id') diff --git a/tempest_lib/tests/services/compute/test_security_groups_client.py b/tempest_lib/tests/services/compute/test_security_groups_client.py deleted file mode 100644 index 1d44b89..0000000 --- a/tempest_lib/tests/services/compute/test_security_groups_client.py +++ /dev/null @@ -1,113 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslotest import mockpatch - -from tempest_lib import exceptions as lib_exc -from tempest_lib.services.compute import security_groups_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestSecurityGroupsClient(base.BaseComputeServiceTest): - - FAKE_SECURITY_GROUP_INFO = [{ - "description": "default", - "id": "3fb26eb3-581b-4420-9963-b0879a026506", - "name": "default", - "rules": [], - "tenant_id": "openstack" - }] - - def setUp(self): - super(TestSecurityGroupsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = security_groups_client.SecurityGroupsClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_security_groups(self, bytes_body=False): - self.check_service_client_function( - self.client.list_security_groups, - 'tempest_lib.common.rest_client.RestClient.get', - {"security_groups": self.FAKE_SECURITY_GROUP_INFO}, - to_utf=bytes_body) - - def test_list_security_groups_with_str_body(self): - self._test_list_security_groups() - - def test_list_security_groups_with_bytes_body(self): - self._test_list_security_groups(bytes_body=True) - - def _test_show_security_group(self, bytes_body=False): - self.check_service_client_function( - self.client.show_security_group, - 'tempest_lib.common.rest_client.RestClient.get', - {"security_group": self.FAKE_SECURITY_GROUP_INFO[0]}, - to_utf=bytes_body, - security_group_id='fake-id') - - def test_show_security_group_with_str_body(self): - self._test_show_security_group() - - def test_show_security_group_with_bytes_body(self): - self._test_show_security_group(bytes_body=True) - - def _test_create_security_group(self, bytes_body=False): - post_body = {"name": "test", "description": "test_group"} - self.check_service_client_function( - self.client.create_security_group, - 'tempest_lib.common.rest_client.RestClient.post', - {"security_group": self.FAKE_SECURITY_GROUP_INFO[0]}, - to_utf=bytes_body, - kwargs=post_body) - - def test_create_security_group_with_str_body(self): - self._test_create_security_group() - - def test_create_security_group_with_bytes_body(self): - self._test_create_security_group(bytes_body=True) - - def _test_update_security_group(self, bytes_body=False): - req_body = {"name": "test", "description": "test_group"} - self.check_service_client_function( - self.client.update_security_group, - 'tempest_lib.common.rest_client.RestClient.put', - {"security_group": self.FAKE_SECURITY_GROUP_INFO[0]}, - to_utf=bytes_body, - security_group_id='fake-id', - kwargs=req_body) - - def test_update_security_group_with_str_body(self): - self._test_update_security_group() - - def test_update_security_group_with_bytes_body(self): - self._test_update_security_group(bytes_body=True) - - def test_delete_security_group(self): - self.check_service_client_function( - self.client.delete_security_group, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=202, security_group_id='fake-id') - - def test_is_resource_deleted_true(self): - mod = ('tempest_lib.services.compute.security_groups_client.' - 'SecurityGroupsClient.show_security_group') - self.useFixture(mockpatch.Patch(mod, side_effect=lib_exc.NotFound)) - self.assertTrue(self.client.is_resource_deleted('fake-id')) - - def test_is_resource_deleted_false(self): - mod = ('tempest_lib.services.compute.security_groups_client.' - 'SecurityGroupsClient.show_security_group') - self.useFixture(mockpatch.Patch(mod, return_value='success')) - self.assertFalse(self.client.is_resource_deleted('fake-id')) diff --git a/tempest_lib/tests/services/compute/test_server_groups_client.py b/tempest_lib/tests/services/compute/test_server_groups_client.py deleted file mode 100644 index 93e1bde..0000000 --- a/tempest_lib/tests/services/compute/test_server_groups_client.py +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2015 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import httplib2 - -from oslotest import mockpatch -from tempest_lib.tests import fake_auth_provider - -from tempest_lib.services.compute import server_groups_client -from tempest_lib.tests.services.compute import base - - -class TestServerGroupsClient(base.BaseComputeServiceTest): - - server_group = { - "id": "5bbcc3c4-1da2-4437-a48a-66f15b1b13f9", - "name": "test", - "policies": ["anti-affinity"], - "members": [], - "metadata": {}} - - def setUp(self): - super(TestServerGroupsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = server_groups_client.ServerGroupsClient( - fake_auth, 'compute', 'regionOne') - - def _test_create_server_group(self, bytes_body=False): - expected = {"server_group": TestServerGroupsClient.server_group} - self.check_service_client_function( - self.client.create_server_group, - 'tempest_lib.common.rest_client.RestClient.post', expected, - bytes_body, name='fake-group', policies=['affinity']) - - def test_create_server_group_str_body(self): - self._test_create_server_group(bytes_body=False) - - def test_create_server_group_byte_body(self): - self._test_create_server_group(bytes_body=True) - - def test_delete_server_group(self): - response = (httplib2.Response({'status': 204}), None) - self.useFixture(mockpatch.Patch( - 'tempest_lib.common.rest_client.RestClient.delete', - return_value=response)) - self.client.delete_server_group('fake-group') - - def _test_list_server_groups(self, bytes_body=False): - expected = {"server_groups": [TestServerGroupsClient.server_group]} - self.check_service_client_function( - self.client.list_server_groups, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body) - - def test_list_server_groups_str_body(self): - self._test_list_server_groups(bytes_body=False) - - def test_list_server_groups_byte_body(self): - self._test_list_server_groups(bytes_body=True) - - def _test_show_server_group(self, bytes_body=False): - expected = {"server_group": TestServerGroupsClient.server_group} - self.check_service_client_function( - self.client.show_server_group, - 'tempest_lib.common.rest_client.RestClient.get', - expected, bytes_body, - server_group_id='5bbcc3c4-1da2-4437-a48a-66f15b1b13f9') - - def test_show_server_group_str_body(self): - self._test_show_server_group(bytes_body=False) - - def test_show_server_group_byte_body(self): - self._test_show_server_group(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_servers_client.py b/tempest_lib/tests/services/compute/test_servers_client.py deleted file mode 100644 index d3a4e83..0000000 --- a/tempest_lib/tests/services/compute/test_servers_client.py +++ /dev/null @@ -1,1011 +0,0 @@ -# Copyright 2015 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from tempest_lib.services.compute import servers_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestServersClient(base.BaseComputeServiceTest): - - FAKE_SERVERS = {'servers': [{ - "id": "616fb98f-46ca-475e-917e-2563e5a8cd19", - "links": [ - { - "href": "http://os.co/v2/616fb98f-46ca-475e-917e-2563e5a8cd19", - "rel": "self" - }, - { - "href": "http://os.co/616fb98f-46ca-475e-917e-2563e5a8cd19", - "rel": "bookmark" - } - ], - "name": u"new\u1234-server-test"}] - } - - FAKE_SERVER_DIAGNOSTICS = { - "cpu0_time": 17300000000, - "memory": 524288, - "vda_errors": -1, - "vda_read": 262144, - "vda_read_req": 112, - "vda_write": 5778432, - "vda_write_req": 488, - "vnet1_rx": 2070139, - "vnet1_rx_drop": 0, - "vnet1_rx_errors": 0, - "vnet1_rx_packets": 26701, - "vnet1_tx": 140208, - "vnet1_tx_drop": 0, - "vnet1_tx_errors": 0, - "vnet1_tx_packets": 662 - } - - FAKE_SERVER_GET = {'server': { - "accessIPv4": "", - "accessIPv6": "", - "addresses": { - "private": [ - { - "addr": "192.168.0.3", - "version": 4 - } - ] - }, - "created": "2012-08-20T21:11:09Z", - "flavor": { - "id": "1", - "links": [ - { - "href": "http://os.com/openstack/flavors/1", - "rel": "bookmark" - } - ] - }, - "hostId": "65201c14a29663e06d0748e561207d998b343e1d164bfa0aafa9c45d", - "id": "893c7791-f1df-4c3d-8383-3caae9656c62", - "image": { - "id": "70a599e0-31e7-49b7-b260-868f441e862b", - "links": [ - { - "href": "http://imgs/70a599e0-31e7-49b7-b260-868f441e862b", - "rel": "bookmark" - } - ] - }, - "links": [ - { - "href": "http://v2/srvs/893c7791-f1df-4c3d-8383-3caae9656c62", - "rel": "self" - }, - { - "href": "http://srvs/893c7791-f1df-4c3d-8383-3caae9656c62", - "rel": "bookmark" - } - ], - "metadata": { - u"My Server N\u1234me": u"Apa\u1234che1" - }, - "name": u"new\u1234-server-test", - "progress": 0, - "status": "ACTIVE", - "tenant_id": "openstack", - "updated": "2012-08-20T21:11:09Z", - "user_id": "fake"} - } - - FAKE_SERVER_POST = {"server": { - "id": "616fb98f-46ca-475e-917e-2563e5a8cd19", - "adminPass": "fake-admin-pass", - "security_groups": [ - 'fake-security-group-1', - 'fake-security-group-2' - ], - "links": [ - { - "href": "http://os.co/v2/616fb98f-46ca-475e-917e-2563e5a8cd19", - "rel": "self" - }, - { - "href": "http://os.co/616fb98f-46ca-475e-917e-2563e5a8cd19", - "rel": "bookmark" - } - ], - "OS-DCF:diskConfig": "fake-disk-config"} - } - - FAKE_ADDRESS = {"addresses": { - "private": [ - { - "addr": "192.168.0.3", - "version": 4 - } - ]} - } - - FAKE_COMMON_VOLUME = { - "id": "a6b0875b-6b5d-4a5a-81eb-0c3aa62e5fdb", - "device": "fake-device", - "volumeId": "a6b0875b-46ca-475e-917e-0c3aa62e5fdb", - "serverId": "616fb98f-46ca-475e-917e-2563e5a8cd19" - } - - FAKE_VIRTUAL_INTERFACES = { - "id": "a6b0875b-46ca-475e-917e-0c3aa62e5fdb", - "mac_address": "00:25:90:5b:f8:c3", - "OS-EXT-VIF-NET:net_id": "fake-os-net-id" - } - - FAKE_INSTANCE_ACTIONS = { - "action": "fake-action", - "request_id": "16fb98f-46ca-475e-917e-2563e5a8cd19", - "user_id": "16fb98f-46ca-475e-917e-2563e5a8cd12", - "project_id": "16fb98f-46ca-475e-917e-2563e5a8cd34", - "start_time": "09MAR2015 11:15", - "message": "fake-msg", - "instance_uuid": "16fb98f-46ca-475e-917e-2563e5a8cd12" - } - - FAKE_VNC_CONSOLE = { - "type": "fake-type", - "url": "http://os.co/v2/616fb98f-46ca-475e-917e-2563e5a8cd19" - } - - FAKE_INSTANCE_ACTION_EVENTS = { - "event": "fake-event", - "start_time": "09MAR2015 11:15", - "finish_time": "09MAR2015 11:15", - "result": "fake-result", - "traceback": "fake-trace-back" - } - - FAKE_INSTANCE_WITH_EVENTS = copy.deepcopy(FAKE_INSTANCE_ACTIONS) - FAKE_INSTANCE_WITH_EVENTS['events'] = [FAKE_INSTANCE_ACTION_EVENTS] - - FAKE_REBUILD_SERVER = copy.deepcopy(FAKE_SERVER_GET) - FAKE_REBUILD_SERVER['server']['adminPass'] = 'fake-admin-pass' - - server_id = FAKE_SERVER_GET['server']['id'] - network_id = 'a6b0875b-6b5d-4a5a-81eb-0c3aa62e5fdb' - - def setUp(self): - super(TestServersClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = servers_client.ServersClient( - fake_auth, 'compute', 'regionOne') - - def test_list_servers_with_str_body(self): - self._test_list_servers() - - def test_list_servers_with_bytes_body(self): - self._test_list_servers(bytes_body=True) - - def _test_list_servers(self, bytes_body=False): - self.check_service_client_function( - self.client.list_servers, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_SERVERS, - bytes_body) - - def test_show_server_with_str_body(self): - self._test_show_server() - - def test_show_server_with_bytes_body(self): - self._test_show_server(bytes_body=True) - - def _test_show_server(self, bytes_body=False): - self.check_service_client_function( - self.client.show_server, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_SERVER_GET, - bytes_body, - server_id=self.server_id - ) - - def test_delete_server(self, bytes_body=False): - self.check_service_client_function( - self.client.delete_server, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, - status=204, - server_id=self.server_id - ) - - def test_create_server_with_str_body(self): - self._test_create_server() - - def test_create_server_with_bytes_body(self): - self._test_create_server(True) - - def _test_create_server(self, bytes_body=False): - self.check_service_client_function( - self.client.create_server, - 'tempest_lib.common.rest_client.RestClient.post', - self.FAKE_SERVER_POST, - bytes_body, - status=202, - name='fake-name', - imageRef='fake-image-ref', - flavorRef='fake-flavor-ref' - ) - - def test_list_addresses_with_str_body(self): - self._test_list_addresses() - - def test_list_addresses_with_bytes_body(self): - self._test_list_addresses(True) - - def _test_list_addresses(self, bytes_body=False): - self.check_service_client_function( - self.client.list_addresses, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_ADDRESS, - bytes_body, - server_id=self.server_id - ) - - def test_list_addresses_by_network_with_str_body(self): - self._test_list_addresses_by_network() - - def test_list_addresses_by_network_with_bytes_body(self): - self._test_list_addresses_by_network(True) - - def _test_list_addresses_by_network(self, bytes_body=False): - self.check_service_client_function( - self.client.list_addresses_by_network, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_ADDRESS['addresses'], - server_id=self.server_id, - network_id=self.network_id - ) - - def test_action_with_str_body(self): - self._test_action() - - def test_action_with_bytes_body(self): - self._test_action(True) - - def _test_action(self, bytes_body=False): - self.check_service_client_function( - self.client.action, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - server_id=self.server_id, - action_name='fake-action-name', - schema={'status_code': 200} - ) - - def test_create_backup_with_str_body(self): - self._test_create_backup() - - def test_create_backup_with_bytes_body(self): - self._test_create_backup(True) - - def _test_create_backup(self, bytes_body=False): - self.check_service_client_function( - self.client.create_backup, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id, - backup_type='fake-backup', - rotation='fake-rotation', - name='fake-name' - ) - - def test_change_password_with_str_body(self): - self._test_change_password() - - def test_change_password_with_bytes_body(self): - self._test_change_password(True) - - def _test_change_password(self, bytes_body=False): - self.check_service_client_function( - self.client.change_password, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id, - adminPass='fake-admin-pass' - ) - - def test_show_password_with_str_body(self): - self._test_show_password() - - def test_show_password_with_bytes_body(self): - self._test_show_password(True) - - def _test_show_password(self, bytes_body=False): - self.check_service_client_function( - self.client.show_password, - 'tempest_lib.common.rest_client.RestClient.get', - {'password': 'fake-password'}, - server_id=self.server_id - ) - - def test_delete_password_with_str_body(self): - self._test_delete_password() - - def test_delete_password_with_bytes_body(self): - self._test_delete_password(True) - - def _test_delete_password(self, bytes_body=False): - self.check_service_client_function( - self.client.delete_password, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, - status=204, - server_id=self.server_id - ) - - def test_reboot_server_with_str_body(self): - self._test_reboot_server() - - def test_reboot_server_with_bytes_body(self): - self._test_reboot_server(True) - - def _test_reboot_server(self, bytes_body=False): - self.check_service_client_function( - self.client.reboot_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id, - type='fake-reboot-type' - ) - - def test_rebuild_server_with_str_body(self): - self._test_rebuild_server() - - def test_rebuild_server_with_bytes_body(self): - self._test_rebuild_server(True) - - def _test_rebuild_server(self, bytes_body=False): - self.check_service_client_function( - self.client.rebuild_server, - 'tempest_lib.common.rest_client.RestClient.post', - self.FAKE_REBUILD_SERVER, - status=202, - server_id=self.server_id, - image_ref='fake-image-ref' - ) - - def test_resize_server_with_str_body(self): - self._test_resize_server() - - def test_resize_server_with_bytes_body(self): - self._test_resize_server(True) - - def _test_resize_server(self, bytes_body=False): - self.check_service_client_function( - self.client.resize_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id, - flavor_ref='fake-flavor-ref' - ) - - def test_confirm_resize_server_with_str_body(self): - self._test_confirm_resize_server() - - def test_confirm_resize_server_with_bytes_body(self): - self._test_confirm_resize_server(True) - - def _test_confirm_resize_server(self, bytes_body=False): - self.check_service_client_function( - self.client.confirm_resize_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=204, - server_id=self.server_id - ) - - def test_revert_resize_server_with_str_body(self): - self._test_revert_resize() - - def test_revert_resize_server_with_bytes_body(self): - self._test_revert_resize(True) - - def _test_revert_resize(self, bytes_body=False): - self.check_service_client_function( - self.client.revert_resize_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_list_server_metadata_with_str_body(self): - self._test_list_server_metadata() - - def test_list_server_metadata_with_bytes_body(self): - self._test_list_server_metadata() - - def _test_list_server_metadata(self, bytes_body=False): - self.check_service_client_function( - self.client.list_server_metadata, - 'tempest_lib.common.rest_client.RestClient.get', - {'metadata': {'fake-key': 'fake-meta-data'}}, - server_id=self.server_id - ) - - def test_set_server_metadata_with_str_body(self): - self._test_set_server_metadata() - - def test_set_server_metadata_with_bytes_body(self): - self._test_set_server_metadata(True) - - def _test_set_server_metadata(self, bytes_body=False): - self.check_service_client_function( - self.client.set_server_metadata, - 'tempest_lib.common.rest_client.RestClient.put', - {'metadata': {'fake-key': 'fake-meta-data'}}, - server_id=self.server_id, - meta='fake-meta' - ) - - def test_update_server_metadata_with_str_body(self): - self._test_update_server_metadata() - - def test_update_server_metadata_with_bytes_body(self): - self._test_update_server_metadata(True) - - def _test_update_server_metadata(self, bytes_body=False): - self.check_service_client_function( - self.client.update_server_metadata, - 'tempest_lib.common.rest_client.RestClient.post', - {'metadata': {'fake-key': 'fake-meta-data'}}, - server_id=self.server_id, - meta='fake-meta' - ) - - def test_show_server_metadata_item_with_str_body(self): - self._test_show_server_metadata() - - def test_show_server_metadata_item_with_bytes_body(self): - self._test_show_server_metadata(True) - - def _test_show_server_metadata(self, bytes_body=False): - self.check_service_client_function( - self.client.show_server_metadata_item, - 'tempest_lib.common.rest_client.RestClient.get', - {'meta': {'fake-key': 'fake-meta-data'}}, - server_id=self.server_id, - key='fake-key' - ) - - def test_set_server_metadata_item_with_str_body(self): - self._test_set_server_metadata_item() - - def test_set_server_metadata_item_with_bytes_body(self): - self._test_set_server_metadata_item(True) - - def _test_set_server_metadata_item(self, bytes_body=False): - self.check_service_client_function( - self.client.set_server_metadata_item, - 'tempest_lib.common.rest_client.RestClient.put', - {'meta': {'fake-key': 'fake-meta-data'}}, - server_id=self.server_id, - key='fake-key', - meta='fake-meta' - ) - - def test_delete_server_metadata_item_with_str_body(self): - self._test_delete_server_metadata() - - def test_delete_server_metadata_item_with_bytes_body(self): - self._test_delete_server_metadata(True) - - def _test_delete_server_metadata(self, bytes_body=False): - self.check_service_client_function( - self.client.delete_server_metadata_item, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, - status=204, - server_id=self.server_id, - key='fake-key' - ) - - def test_stop_server_with_str_body(self): - self._test_stop_server() - - def test_stop_server_with_bytes_body(self): - self._test_stop_server(True) - - def _test_stop_server(self, bytes_body=False): - self.check_service_client_function( - self.client.stop_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_start_server_with_str_body(self): - self._test_start_server() - - def test_start_server_with_bytes_body(self): - self._test_start_server(True) - - def _test_start_server(self, bytes_body=False): - self.check_service_client_function( - self.client.start_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_attach_volume_with_str_body(self): - self._test_attach_volume_server() - - def test_attach_volume_with_bytes_body(self): - self._test_attach_volume_server(True) - - def _test_attach_volume_server(self, bytes_body=False): - self.check_service_client_function( - self.client.attach_volume, - 'tempest_lib.common.rest_client.RestClient.post', - {'volumeAttachment': self.FAKE_COMMON_VOLUME}, - server_id=self.server_id - ) - - def test_update_attached_volume(self): - self.check_service_client_function( - self.client.update_attached_volume, - 'tempest_lib.common.rest_client.RestClient.put', - {}, - status=202, - server_id=self.server_id, - attachment_id='fake-attachment-id', - volumeId='fake-volume-id' - ) - - def test_detach_volume_with_str_body(self): - self._test_detach_volume_server() - - def test_detach_volume_with_bytes_body(self): - self._test_detach_volume_server(True) - - def _test_detach_volume_server(self, bytes_body=False): - self.check_service_client_function( - self.client.detach_volume, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, - status=202, - server_id=self.server_id, - volume_id=self.FAKE_COMMON_VOLUME['volumeId'] - ) - - def test_show_volume_attachment_with_str_body(self): - self._test_show_volume_attachment() - - def test_show_volume_attachment_with_bytes_body(self): - self._test_show_volume_attachment(True) - - def _test_show_volume_attachment(self, bytes_body=False): - self.check_service_client_function( - self.client.show_volume_attachment, - 'tempest_lib.common.rest_client.RestClient.get', - {'volumeAttachment': self.FAKE_COMMON_VOLUME}, - server_id=self.server_id, - volume_id=self.FAKE_COMMON_VOLUME['volumeId'] - ) - - def test_list_volume_attachments_with_str_body(self): - self._test_list_volume_attachments() - - def test_list_volume_attachments_with_bytes_body(self): - self._test_list_volume_attachments(True) - - def _test_list_volume_attachments(self, bytes_body=False): - self.check_service_client_function( - self.client.list_volume_attachments, - 'tempest_lib.common.rest_client.RestClient.get', - {'volumeAttachments': [self.FAKE_COMMON_VOLUME]}, - server_id=self.server_id - ) - - def test_add_security_group_with_str_body(self): - self._test_add_security_group() - - def test_add_security_group_with_bytes_body(self): - self._test_add_security_group(True) - - def _test_add_security_group(self, bytes_body=False): - self.check_service_client_function( - self.client.add_security_group, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id, - name='fake-name' - ) - - def test_remove_security_group_with_str_body(self): - self._test_remove_security_group() - - def test_remove_security_group_with_bytes_body(self): - self._test_remove_security_group(True) - - def _test_remove_security_group(self, bytes_body=False): - self.check_service_client_function( - self.client.remove_security_group, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id, - name='fake-name' - ) - - def test_live_migrate_server_with_str_body(self): - self._test_live_migrate_server() - - def test_live_migrate_server_with_bytes_body(self): - self._test_live_migrate_server(True) - - def _test_live_migrate_server(self, bytes_body=False): - self.check_service_client_function( - self.client.live_migrate_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_migrate_server_with_str_body(self): - self._test_migrate_server() - - def test_migrate_server_with_bytes_body(self): - self._test_migrate_server(True) - - def _test_migrate_server(self, bytes_body=False): - self.check_service_client_function( - self.client.migrate_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_lock_server_with_str_body(self): - self._test_lock_server() - - def test_lock_server_with_bytes_body(self): - self._test_lock_server(True) - - def _test_lock_server(self, bytes_body=False): - self.check_service_client_function( - self.client.lock_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_unlock_server_with_str_body(self): - self._test_unlock_server() - - def test_unlock_server_with_bytes_body(self): - self._test_unlock_server(True) - - def _test_unlock_server(self, bytes_body=False): - self.check_service_client_function( - self.client.unlock_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_suspend_server_with_str_body(self): - self._test_suspend_server() - - def test_suspend_server_with_bytes_body(self): - self._test_suspend_server(True) - - def _test_suspend_server(self, bytes_body=False): - self.check_service_client_function( - self.client.suspend_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_resume_server_with_str_body(self): - self._test_resume_server() - - def test_resume_server_with_bytes_body(self): - self._test_resume_server(True) - - def _test_resume_server(self, bytes_body=False): - self.check_service_client_function( - self.client.resume_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_pause_server_with_str_body(self): - self._test_pause_server() - - def test_pause_server_with_bytes_body(self): - self._test_pause_server(True) - - def _test_pause_server(self, bytes_body=False): - self.check_service_client_function( - self.client.pause_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_unpause_server_with_str_body(self): - self._test_unpause_server() - - def test_unpause_server_with_bytes_body(self): - self._test_unpause_server(True) - - def _test_unpause_server(self, bytes_body=False): - self.check_service_client_function( - self.client.unpause_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_reset_state_with_str_body(self): - self._test_reset_state() - - def test_reset_state_with_bytes_body(self): - self._test_reset_state(True) - - def _test_reset_state(self, bytes_body=False): - self.check_service_client_function( - self.client.reset_state, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id, - state='fake-state' - ) - - def test_shelve_server_with_str_body(self): - self._test_shelve_server() - - def test_shelve_server_with_bytes_body(self): - self._test_shelve_server(True) - - def _test_shelve_server(self, bytes_body=False): - self.check_service_client_function( - self.client.shelve_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_unshelve_server_with_str_body(self): - self._test_unshelve_server() - - def test_unshelve_server_with_bytes_body(self): - self._test_unshelve_server(True) - - def _test_unshelve_server(self, bytes_body=False): - self.check_service_client_function( - self.client.unshelve_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_shelve_offload_server_with_str_body(self): - self._test_shelve_offload_server() - - def test_shelve_offload_server_with_bytes_body(self): - self._test_shelve_offload_server(True) - - def _test_shelve_offload_server(self, bytes_body=False): - self.check_service_client_function( - self.client.shelve_offload_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_get_console_output_with_str_body(self): - self._test_get_console_output() - - def test_get_console_output_with_bytes_body(self): - self._test_get_console_output(True) - - def _test_get_console_output(self, bytes_body=False): - self.check_service_client_function( - self.client.get_console_output, - 'tempest_lib.common.rest_client.RestClient.post', - {'output': 'fake-output'}, - server_id=self.server_id, - length='fake-length' - ) - - def test_list_virtual_interfaces_with_str_body(self): - self._test_list_virtual_interfaces() - - def test_list_virtual_interfaces_with_bytes_body(self): - self._test_list_virtual_interfaces(True) - - def _test_list_virtual_interfaces(self, bytes_body=False): - self.check_service_client_function( - self.client.list_virtual_interfaces, - 'tempest_lib.common.rest_client.RestClient.get', - {'virtual_interfaces': [self.FAKE_VIRTUAL_INTERFACES]}, - server_id=self.server_id - ) - - def test_rescue_server_with_str_body(self): - self._test_rescue_server() - - def test_rescue_server_with_bytes_body(self): - self._test_rescue_server(True) - - def _test_rescue_server(self, bytes_body=False): - self.check_service_client_function( - self.client.rescue_server, - 'tempest_lib.common.rest_client.RestClient.post', - {'adminPass': 'fake-admin-pass'}, - server_id=self.server_id - ) - - def test_unrescue_server_with_str_body(self): - self._test_unrescue_server() - - def test_unrescue_server_with_bytes_body(self): - self._test_unrescue_server(True) - - def _test_unrescue_server(self, bytes_body=False): - self.check_service_client_function( - self.client.unrescue_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_show_server_diagnostics_with_str_body(self): - self._test_show_server_diagnostics() - - def test_show_server_diagnostics_with_bytes_body(self): - self._test_show_server_diagnostics(True) - - def _test_show_server_diagnostics(self, bytes_body=False): - self.check_service_client_function( - self.client.show_server_diagnostics, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_SERVER_DIAGNOSTICS, - status=200, - server_id=self.server_id - ) - - def test_list_instance_actions_with_str_body(self): - self._test_list_instance_actions() - - def test_list_instance_actions_with_bytes_body(self): - self._test_list_instance_actions(True) - - def _test_list_instance_actions(self, bytes_body=False): - self.check_service_client_function( - self.client.list_instance_actions, - 'tempest_lib.common.rest_client.RestClient.get', - {'instanceActions': [self.FAKE_INSTANCE_ACTIONS]}, - server_id=self.server_id - ) - - def test_show_instance_action_with_str_body(self): - self._test_show_instance_action() - - def test_show_instance_action_with_bytes_body(self): - self._test_show_instance_action(True) - - def _test_show_instance_action(self, bytes_body=False): - self.check_service_client_function( - self.client.show_instance_action, - 'tempest_lib.common.rest_client.RestClient.get', - {'instanceAction': self.FAKE_INSTANCE_WITH_EVENTS}, - server_id=self.server_id, - request_id='fake-request-id' - ) - - def test_force_delete_server_with_str_body(self): - self._test_force_delete_server() - - def test_force_delete_server_with_bytes_body(self): - self._test_force_delete_server(True) - - def _test_force_delete_server(self, bytes_body=False): - self.check_service_client_function( - self.client.force_delete_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_restore_soft_deleted_server_with_str_body(self): - self._test_restore_soft_deleted_server() - - def test_restore_soft_deleted_server_with_bytes_body(self): - self._test_restore_soft_deleted_server(True) - - def _test_restore_soft_deleted_server(self, bytes_body=False): - self.check_service_client_function( - self.client.restore_soft_deleted_server, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_reset_network_with_str_body(self): - self._test_reset_network() - - def test_reset_network_with_bytes_body(self): - self._test_reset_network(True) - - def _test_reset_network(self, bytes_body=False): - self.check_service_client_function( - self.client.reset_network, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_inject_network_info_with_str_body(self): - self._test_inject_network_info() - - def test_inject_network_info_with_bytes_body(self): - self._test_inject_network_info(True) - - def _test_inject_network_info(self, bytes_body=False): - self.check_service_client_function( - self.client.inject_network_info, - 'tempest_lib.common.rest_client.RestClient.post', - {}, - status=202, - server_id=self.server_id - ) - - def test_get_vnc_console_with_str_body(self): - self._test_get_vnc_console() - - def test_get_vnc_console_with_bytes_body(self): - self._test_get_vnc_console(True) - - def _test_get_vnc_console(self, bytes_body=False): - self.check_service_client_function( - self.client.get_vnc_console, - 'tempest_lib.common.rest_client.RestClient.post', - {'console': self.FAKE_VNC_CONSOLE}, - server_id=self.server_id, - type='fake-console-type' - ) diff --git a/tempest_lib/tests/services/compute/test_services_client.py b/tempest_lib/tests/services/compute/test_services_client.py deleted file mode 100644 index 67d717a..0000000 --- a/tempest_lib/tests/services/compute/test_services_client.py +++ /dev/null @@ -1,94 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from tempest_lib.services.compute import services_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestServicesClient(base.BaseComputeServiceTest): - - FAKE_SERVICES = { - "services": - [{ - "status": "enabled", - "binary": "nova-conductor", - "zone": "internal", - "state": "up", - "updated_at": "2015-08-19T06:50:55.000000", - "host": "controller", - "disabled_reason": None, - "id": 1 - }] - } - - FAKE_SERVICE = { - "service": - { - "status": "enabled", - "binary": "nova-conductor", - "host": "controller" - } - } - - def setUp(self): - super(TestServicesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = services_client.ServicesClient( - fake_auth, 'compute', 'regionOne') - - def test_list_services_with_str_body(self): - self.check_service_client_function( - self.client.list_services, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_SERVICES) - - def test_list_services_with_bytes_body(self): - self.check_service_client_function( - self.client.list_services, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_SERVICES, to_utf=True) - - def _test_enable_service(self, bytes_body=False): - self.check_service_client_function( - self.client.enable_service, - 'tempest_lib.common.rest_client.RestClient.put', - self.FAKE_SERVICE, - bytes_body, - host_name="nova-conductor", binary="controller") - - def test_enable_service_with_str_body(self): - self._test_enable_service() - - def test_enable_service_with_bytes_body(self): - self._test_enable_service(bytes_body=True) - - def _test_disable_service(self, bytes_body=False): - fake_service = copy.deepcopy(self.FAKE_SERVICE) - fake_service["service"]["status"] = "disable" - - self.check_service_client_function( - self.client.disable_service, - 'tempest_lib.common.rest_client.RestClient.put', - fake_service, - bytes_body, - host_name="nova-conductor", binary="controller") - - def test_disable_service_with_str_body(self): - self._test_disable_service() - - def test_disable_service_with_bytes_body(self): - self._test_disable_service(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_snapshots_client.py b/tempest_lib/tests/services/compute/test_snapshots_client.py deleted file mode 100644 index 008a7ea..0000000 --- a/tempest_lib/tests/services/compute/test_snapshots_client.py +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from oslotest import mockpatch - -from tempest_lib import exceptions as lib_exc -from tempest_lib.services.compute import snapshots_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestSnapshotsClient(base.BaseComputeServiceTest): - - FAKE_SNAPSHOT = { - "createdAt": "2015-10-02T16:27:54.724209", - "displayDescription": u"Another \u1234.", - "displayName": u"v\u1234-001", - "id": "100", - "size": 100, - "status": "available", - "volumeId": "12" - } - - FAKE_SNAPSHOTS = {"snapshots": [FAKE_SNAPSHOT]} - - def setUp(self): - super(TestSnapshotsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = snapshots_client.SnapshotsClient( - fake_auth, 'compute', 'regionOne') - - def _test_create_snapshot(self, bytes_body=False): - self.check_service_client_function( - self.client.create_snapshot, - 'tempest_lib.common.rest_client.RestClient.post', - {"snapshot": self.FAKE_SNAPSHOT}, - to_utf=bytes_body, status=200, - volume_id=self.FAKE_SNAPSHOT["volumeId"]) - - def test_create_snapshot_with_str_body(self): - self._test_create_snapshot() - - def test_create_shapshot_with_bytes_body(self): - self._test_create_snapshot(bytes_body=True) - - def _test_show_snapshot(self, bytes_body=False): - self.check_service_client_function( - self.client.show_snapshot, - 'tempest_lib.common.rest_client.RestClient.get', - {"snapshot": self.FAKE_SNAPSHOT}, - to_utf=bytes_body, snapshot_id=self.FAKE_SNAPSHOT["id"]) - - def test_show_snapshot_with_str_body(self): - self._test_show_snapshot() - - def test_show_snapshot_with_bytes_body(self): - self._test_show_snapshot(bytes_body=True) - - def _test_list_snapshots(self, bytes_body=False, **params): - self.check_service_client_function( - self.client.list_snapshots, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_SNAPSHOTS, to_utf=bytes_body, **params) - - def test_list_snapshots_with_str_body(self): - self._test_list_snapshots() - - def test_list_snapshots_with_byte_body(self): - self._test_list_snapshots(bytes_body=True) - - def test_list_snapshots_with_params(self): - self._test_list_snapshots('fake') - - def test_delete_snapshot(self): - self.check_service_client_function( - self.client.delete_snapshot, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=202, snapshot_id=self.FAKE_SNAPSHOT['id']) - - def test_is_resource_deleted_true(self): - module = ('tempest_lib.services.compute.snapshots_client.' - 'SnapshotsClient.show_snapshot') - self.useFixture(mockpatch.Patch( - module, side_effect=lib_exc.NotFound)) - self.assertTrue(self.client.is_resource_deleted('fake-id')) - - def test_is_resource_deleted_false(self): - module = ('tempest_lib.services.compute.snapshots_client.' - 'SnapshotsClient.show_snapshot') - self.useFixture(mockpatch.Patch( - module, return_value={})) - self.assertFalse(self.client.is_resource_deleted('fake-id')) diff --git a/tempest_lib/tests/services/compute/test_tenant_networks_client.py b/tempest_lib/tests/services/compute/test_tenant_networks_client.py deleted file mode 100644 index d21d85c..0000000 --- a/tempest_lib/tests/services/compute/test_tenant_networks_client.py +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import tenant_networks_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestTenantNetworksClient(base.BaseComputeServiceTest): - - FAKE_NETWORK = { - "cidr": "None", - "id": "c2329eb4-cc8e-4439-ac4c-932369309e36", - "label": u'\u30d7' - } - - FAKE_NETWORKS = [FAKE_NETWORK] - - NETWORK_ID = FAKE_NETWORK['id'] - - def setUp(self): - super(TestTenantNetworksClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = tenant_networks_client.TenantNetworksClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_tenant_networks(self, bytes_body=False): - self.check_service_client_function( - self.client.list_tenant_networks, - 'tempest_lib.common.rest_client.RestClient.get', - {"networks": self.FAKE_NETWORKS}, - bytes_body) - - def test_list_tenant_networks_with_str_body(self): - self._test_list_tenant_networks() - - def test_list_tenant_networks_with_bytes_body(self): - self._test_list_tenant_networks(bytes_body=True) - - def _test_show_tenant_network(self, bytes_body=False): - self.check_service_client_function( - self.client.show_tenant_network, - 'tempest_lib.common.rest_client.RestClient.get', - {"network": self.FAKE_NETWORK}, - bytes_body, - network_id=self.NETWORK_ID) - - def test_show_tenant_network_with_str_body(self): - self._test_show_tenant_network() - - def test_show_tenant_network_with_bytes_body(self): - self._test_show_tenant_network(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_tenant_usages_client.py b/tempest_lib/tests/services/compute/test_tenant_usages_client.py deleted file mode 100644 index 9ccb392..0000000 --- a/tempest_lib/tests/services/compute/test_tenant_usages_client.py +++ /dev/null @@ -1,79 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from tempest_lib.services.compute import tenant_usages_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestTenantUsagesClient(base.BaseComputeServiceTest): - - FAKE_SERVER_USAGES = [{ - "ended_at": None, - "flavor": "m1.tiny", - "hours": 1.0, - "instance_id": "1f1deceb-17b5-4c04-84c7-e0d4499c8fe0", - "local_gb": 1, - "memory_mb": 512, - "name": "new-server-test", - "started_at": "2012-10-08T20:10:44.541277", - "state": "active", - "tenant_id": "openstack", - "uptime": 3600, - "vcpus": 1 - }] - - FAKE_TENANT_USAGES = [{ - "server_usages": FAKE_SERVER_USAGES, - "start": "2012-10-08T21:10:44.587336", - "stop": "2012-10-08T22:10:44.587336", - "tenant_id": "openstack", - "total_hours": 1, - "total_local_gb_usage": 1, - "total_memory_mb_usage": 512, - "total_vcpus_usage": 1 - }] - - def setUp(self): - super(TestTenantUsagesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = tenant_usages_client.TenantUsagesClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_tenant_usages(self, bytes_body=False): - self.check_service_client_function( - self.client.list_tenant_usages, - 'tempest_lib.common.rest_client.RestClient.get', - {"tenant_usages": self.FAKE_TENANT_USAGES}, - to_utf=bytes_body) - - def test_list_tenant_usages_with_str_body(self): - self._test_list_tenant_usages() - - def test_list_tenant_usages_with_bytes_body(self): - self._test_list_tenant_usages(bytes_body=True) - - def _test_show_tenant_usage(self, bytes_body=False): - self.check_service_client_function( - self.client.show_tenant_usage, - 'tempest_lib.common.rest_client.RestClient.get', - {"tenant_usage": self.FAKE_TENANT_USAGES[0]}, - to_utf=bytes_body, - tenant_id='openstack') - - def test_show_tenant_usage_with_str_body(self): - self._test_show_tenant_usage() - - def test_show_tenant_usage_with_bytes_body(self): - self._test_show_tenant_usage(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_versions_client.py b/tempest_lib/tests/services/compute/test_versions_client.py deleted file mode 100644 index f79934e..0000000 --- a/tempest_lib/tests/services/compute/test_versions_client.py +++ /dev/null @@ -1,96 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy -from oslotest import mockpatch - -from tempest_lib.services.compute import versions_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestVersionsClient(base.BaseComputeServiceTest): - - FAKE_INIT_VERSION = { - "version": { - "id": "v2.1", - "links": [ - { - "href": "http://openstack.example.com/v2.1/", - "rel": "self" - }, - { - "href": "http://docs.openstack.org/", - "rel": "describedby", - "type": "text/html" - } - ], - "status": "CURRENT", - "updated": "2013-07-23T11:33:21Z", - "version": "2.1", - "min_version": "2.1" - } - } - - FAKE_VERSIONS_INFO = { - "versions": [FAKE_INIT_VERSION["version"]] - } - - FAKE_VERSION_INFO = copy.deepcopy(FAKE_INIT_VERSION) - - FAKE_VERSION_INFO["version"]["media-types"] = [ - { - "base": "application/json", - "type": "application/vnd.openstack.compute+json;version=2.1" - } - ] - - def setUp(self): - super(TestVersionsClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.versions_client = ( - versions_client.VersionsClient - (fake_auth, 'compute', 'regionOne')) - - def _test_versions_client(self, bytes_body=False): - self.check_service_client_function( - self.versions_client.list_versions, - 'tempest_lib.common.rest_client.RestClient.raw_request', - self.FAKE_VERSIONS_INFO, - bytes_body, - 200) - - def _test_get_version_by_url(self, bytes_body=False): - self.useFixture(mockpatch.Patch( - "tempest_lib.common.rest_client.RestClient.token", - return_value="Dummy Token")) - params = {"version_url": self.versions_client._get_base_version_url()} - self.check_service_client_function( - self.versions_client.get_version_by_url, - 'tempest_lib.common.rest_client.RestClient.raw_request', - self.FAKE_VERSION_INFO, - bytes_body, - 200, **params) - - def test_list_versions_client_with_str_body(self): - self._test_versions_client() - - def test_list_versions_client_with_bytes_body(self): - self._test_versions_client(bytes_body=True) - - def test_get_version_by_url_with_str_body(self): - self._test_get_version_by_url() - - def test_get_version_by_url_with_bytes_body(self): - self._test_get_version_by_url(bytes_body=True) diff --git a/tempest_lib/tests/services/compute/test_volumes_client.py b/tempest_lib/tests/services/compute/test_volumes_client.py deleted file mode 100644 index 0687f35..0000000 --- a/tempest_lib/tests/services/compute/test_volumes_client.py +++ /dev/null @@ -1,114 +0,0 @@ -# Copyright 2015 NEC Corporation. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from oslotest import mockpatch - -from tempest_lib import exceptions as lib_exc -from tempest_lib.services.compute import volumes_client -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests.services.compute import base - - -class TestVolumesClient(base.BaseComputeServiceTest): - - FAKE_VOLUME = { - "id": "521752a6-acf6-4b2d-bc7a-119f9148cd8c", - "displayName": u"v\u12345ol-001", - "displayDescription": u"Another \u1234volume.", - "size": 30, - "status": "Active", - "volumeType": "289da7f8-6440-407c-9fb4-7db01ec49164", - "metadata": { - "contents": "junk" - }, - "availabilityZone": "us-east1", - "snapshotId": None, - "attachments": [], - "createdAt": "2012-02-14T20:53:07Z" - } - - FAKE_VOLUMES = {"volumes": [FAKE_VOLUME]} - - def setUp(self): - super(TestVolumesClient, self).setUp() - fake_auth = fake_auth_provider.FakeAuthProvider() - self.client = volumes_client.VolumesClient( - fake_auth, 'compute', 'regionOne') - - def _test_list_volumes(self, bytes_body=False, **params): - self.check_service_client_function( - self.client.list_volumes, - 'tempest_lib.common.rest_client.RestClient.get', - self.FAKE_VOLUMES, to_utf=bytes_body, **params) - - def test_list_volumes_with_str_body(self): - self._test_list_volumes() - - def test_list_volumes_with_byte_body(self): - self._test_list_volumes(bytes_body=True) - - def test_list_volumes_with_params(self): - self._test_list_volumes(name='fake') - - def _test_show_volume(self, bytes_body=False): - self.check_service_client_function( - self.client.show_volume, - 'tempest_lib.common.rest_client.RestClient.get', - {"volume": self.FAKE_VOLUME}, - to_utf=bytes_body, volume_id=self.FAKE_VOLUME['id']) - - def test_show_volume_with_str_body(self): - self._test_show_volume() - - def test_show_volume_with_bytes_body(self): - self._test_show_volume(bytes_body=True) - - def _test_create_volume(self, bytes_body=False): - post_body = copy.deepcopy(self.FAKE_VOLUME) - del post_body['id'] - del post_body['createdAt'] - del post_body['status'] - self.check_service_client_function( - self.client.create_volume, - 'tempest_lib.common.rest_client.RestClient.post', - {"volume": self.FAKE_VOLUME}, - to_utf=bytes_body, status=200, **post_body) - - def test_create_volume_with_str_body(self): - self._test_create_volume() - - def test_create_volume_with_bytes_body(self): - self._test_create_volume(bytes_body=True) - - def test_delete_volume(self): - self.check_service_client_function( - self.client.delete_volume, - 'tempest_lib.common.rest_client.RestClient.delete', - {}, status=202, volume_id=self.FAKE_VOLUME['id']) - - def test_is_resource_deleted_true(self): - module = ('tempest_lib.services.compute.volumes_client.' - 'VolumesClient.show_volume') - self.useFixture(mockpatch.Patch( - module, side_effect=lib_exc.NotFound)) - self.assertTrue(self.client.is_resource_deleted('fake-id')) - - def test_is_resource_deleted_false(self): - module = ('tempest_lib.services.compute.volumes_client.' - 'VolumesClient.show_volume') - self.useFixture(mockpatch.Patch( - module, return_value={})) - self.assertFalse(self.client.is_resource_deleted('fake-id')) diff --git a/tempest_lib/tests/services/identity/__init__.py b/tempest_lib/tests/services/identity/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/services/identity/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/services/identity/v2/__init__.py b/tempest_lib/tests/services/identity/v2/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/services/identity/v2/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/services/identity/v2/test_token_client.py b/tempest_lib/tests/services/identity/v2/test_token_client.py deleted file mode 100644 index 57e439c..0000000 --- a/tempest_lib/tests/services/identity/v2/test_token_client.py +++ /dev/null @@ -1,92 +0,0 @@ -# Copyright 2015 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import json - -import httplib2 -from oslotest import mockpatch - -from tempest_lib.common import rest_client -from tempest_lib import exceptions -from tempest_lib.services.identity.v2 import token_client -from tempest_lib.tests import base -from tempest_lib.tests import fake_http - - -class TestTokenClientV2(base.TestCase): - - def setUp(self): - super(TestTokenClientV2, self).setUp() - self.fake_200_http = fake_http.fake_httplib2(return_type=200) - - def test_init_without_authurl(self): - self.assertRaises(exceptions.IdentityError, - token_client.TokenClient, None) - - def test_auth(self): - token_client_v2 = token_client.TokenClient('fake_url') - post_mock = self.useFixture(mockpatch.PatchObject( - token_client_v2, 'post', return_value=self.fake_200_http.request( - 'fake_url', body={'access': {'token': 'fake_token'}}))) - resp = token_client_v2.auth('fake_user', 'fake_pass') - self.assertIsInstance(resp, rest_client.ResponseBody) - req_dict = json.dumps({ - 'auth': { - 'passwordCredentials': { - 'username': 'fake_user', - 'password': 'fake_pass', - }, - } - }, sort_keys=True) - post_mock.mock.assert_called_once_with('fake_url/tokens', - body=req_dict) - - def test_auth_with_tenant(self): - token_client_v2 = token_client.TokenClient('fake_url') - post_mock = self.useFixture(mockpatch.PatchObject( - token_client_v2, 'post', return_value=self.fake_200_http.request( - 'fake_url', body={'access': {'token': 'fake_token'}}))) - resp = token_client_v2.auth('fake_user', 'fake_pass', 'fake_tenant') - self.assertIsInstance(resp, rest_client.ResponseBody) - req_dict = json.dumps({ - 'auth': { - 'tenantName': 'fake_tenant', - 'passwordCredentials': { - 'username': 'fake_user', - 'password': 'fake_pass', - }, - } - }, sort_keys=True) - post_mock.mock.assert_called_once_with('fake_url/tokens', - body=req_dict) - - def test_request_with_str_body(self): - token_client_v2 = token_client.TokenClient('fake_url') - self.useFixture(mockpatch.PatchObject( - token_client_v2, 'raw_request', return_value=( - httplib2.Response({'status': '200'}), - str('{"access": {"token": "fake_token"}}')))) - resp, body = token_client_v2.request('GET', 'fake_uri') - self.assertIsInstance(resp, httplib2.Response) - self.assertIsInstance(body, dict) - - def test_request_with_bytes_body(self): - token_client_v2 = token_client.TokenClient('fake_url') - self.useFixture(mockpatch.PatchObject( - token_client_v2, 'raw_request', return_value=( - httplib2.Response({'status': '200'}), - bytes(b'{"access": {"token": "fake_token"}}')))) - resp, body = token_client_v2.request('GET', 'fake_uri') - self.assertIsInstance(resp, httplib2.Response) - self.assertIsInstance(body, dict) diff --git a/tempest_lib/tests/services/identity/v3/__init__.py b/tempest_lib/tests/services/identity/v3/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tempest_lib/tests/services/identity/v3/__init__.py +++ /dev/null diff --git a/tempest_lib/tests/services/identity/v3/test_token_client.py b/tempest_lib/tests/services/identity/v3/test_token_client.py deleted file mode 100644 index b3a8b28..0000000 --- a/tempest_lib/tests/services/identity/v3/test_token_client.py +++ /dev/null @@ -1,145 +0,0 @@ -# Copyright 2015 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import json - -import httplib2 -from oslotest import mockpatch - -from tempest_lib.common import rest_client -from tempest_lib import exceptions -from tempest_lib.services.identity.v3 import token_client -from tempest_lib.tests import base -from tempest_lib.tests import fake_http - - -class TestTokenClientV2(base.TestCase): - - def setUp(self): - super(TestTokenClientV2, self).setUp() - self.fake_201_http = fake_http.fake_httplib2(return_type=201) - - def test_init_without_authurl(self): - self.assertRaises(exceptions.IdentityError, - token_client.V3TokenClient, None) - - def test_auth(self): - token_client_v3 = token_client.V3TokenClient('fake_url') - post_mock = self.useFixture(mockpatch.PatchObject( - token_client_v3, 'post', return_value=self.fake_201_http.request( - 'fake_url', body={'access': {'token': 'fake_token'}}))) - resp = token_client_v3.auth(username='fake_user', password='fake_pass') - self.assertIsInstance(resp, rest_client.ResponseBody) - req_dict = json.dumps({ - 'auth': { - 'identity': { - 'methods': ['password'], - 'password': { - 'user': { - 'name': 'fake_user', - 'password': 'fake_pass', - } - } - }, - } - }, sort_keys=True) - post_mock.mock.assert_called_once_with('fake_url/auth/tokens', - body=req_dict) - - def test_auth_with_project_id_and_domain_id(self): - token_client_v3 = token_client.V3TokenClient('fake_url') - post_mock = self.useFixture(mockpatch.PatchObject( - token_client_v3, 'post', return_value=self.fake_201_http.request( - 'fake_url', body={'access': {'token': 'fake_token'}}))) - resp = token_client_v3.auth( - username='fake_user', password='fake_pass', - project_id='fcac2a055a294e4c82d0a9c21c620eb4', - user_domain_id='14f4a9a99973404d8c20ba1d2af163ff', - project_domain_id='291f63ae9ac54ee292ca09e5f72d9676') - self.assertIsInstance(resp, rest_client.ResponseBody) - req_dict = json.dumps({ - 'auth': { - 'identity': { - 'methods': ['password'], - 'password': { - 'user': { - 'name': 'fake_user', - 'password': 'fake_pass', - 'domain': { - 'id': '14f4a9a99973404d8c20ba1d2af163ff' - } - } - } - }, - 'scope': { - 'project': { - 'id': 'fcac2a055a294e4c82d0a9c21c620eb4', - 'domain': { - 'id': '291f63ae9ac54ee292ca09e5f72d9676' - } - } - } - } - }, sort_keys=True) - post_mock.mock.assert_called_once_with('fake_url/auth/tokens', - body=req_dict) - - def test_auth_with_tenant(self): - token_client_v2 = token_client.V3TokenClient('fake_url') - post_mock = self.useFixture(mockpatch.PatchObject( - token_client_v2, 'post', return_value=self.fake_201_http.request( - 'fake_url', body={'access': {'token': 'fake_token'}}))) - resp = token_client_v2.auth(username='fake_user', password='fake_pass', - project_name='fake_tenant') - self.assertIsInstance(resp, rest_client.ResponseBody) - req_dict = json.dumps({ - 'auth': { - 'identity': { - 'methods': ['password'], - 'password': { - 'user': { - 'name': 'fake_user', - 'password': 'fake_pass', - } - }}, - 'scope': { - 'project': { - 'name': 'fake_tenant' - } - }, - } - }, sort_keys=True) - - post_mock.mock.assert_called_once_with('fake_url/auth/tokens', - body=req_dict) - - def test_request_with_str_body(self): - token_client_v3 = token_client.V3TokenClient('fake_url') - self.useFixture(mockpatch.PatchObject( - token_client_v3, 'raw_request', return_value=( - httplib2.Response({"status": "200"}), - str('{"access": {"token": "fake_token"}}')))) - resp, body = token_client_v3.request('GET', 'fake_uri') - self.assertIsInstance(resp, httplib2.Response) - self.assertIsInstance(body, dict) - - def test_request_with_bytes_body(self): - token_client_v3 = token_client.V3TokenClient('fake_url') - self.useFixture(mockpatch.PatchObject( - token_client_v3, 'raw_request', return_value=( - httplib2.Response({"status": "200"}), - bytes(b'{"access": {"token": "fake_token"}}')))) - resp, body = token_client_v3.request('GET', 'fake_uri') - self.assertIsInstance(resp, httplib2.Response) - self.assertIsInstance(body, dict) diff --git a/tempest_lib/tests/test_auth.py b/tempest_lib/tests/test_auth.py deleted file mode 100644 index 62d95f4..0000000 --- a/tempest_lib/tests/test_auth.py +++ /dev/null @@ -1,480 +0,0 @@ -# Copyright 2014 IBM Corp. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy -import datetime - -from oslotest import mockpatch - -from tempest_lib import auth -from tempest_lib import exceptions -from tempest_lib.services.identity.v2 import token_client as v2_client -from tempest_lib.services.identity.v3 import token_client as v3_client -from tempest_lib.tests import base -from tempest_lib.tests import fake_credentials -from tempest_lib.tests import fake_http -from tempest_lib.tests import fake_identity - - -def fake_get_credentials(fill_in=True, identity_version='v2', **kwargs): - return fake_credentials.FakeCredentials() - - -class BaseAuthTestsSetUp(base.TestCase): - _auth_provider_class = None - credentials = fake_credentials.FakeCredentials() - - def _auth(self, credentials, auth_url, **params): - """returns auth method according to keystone""" - return self._auth_provider_class(credentials, auth_url, **params) - - def setUp(self): - super(BaseAuthTestsSetUp, self).setUp() - self.fake_http = fake_http.fake_httplib2(return_type=200) - self.stubs.Set(auth, 'get_credentials', fake_get_credentials) - self.auth_provider = self._auth(self.credentials, - fake_identity.FAKE_AUTH_URL) - - -class TestBaseAuthProvider(BaseAuthTestsSetUp): - """Tests for base AuthProvider - - This tests auth.AuthProvider class which is base for the other so we - obviously don't test not implemented method or the ones which strongly - depends on them. - """ - - class FakeAuthProviderImpl(auth.AuthProvider): - def _decorate_request(self): - pass - - def _fill_credentials(self): - pass - - def _get_auth(self): - pass - - def base_url(self): - pass - - def is_expired(self): - pass - - _auth_provider_class = FakeAuthProviderImpl - - def _auth(self, credentials, auth_url, **params): - """returns auth method according to keystone""" - return self._auth_provider_class(credentials, **params) - - def test_check_credentials_bad_type(self): - self.assertFalse(self.auth_provider.check_credentials([])) - - def test_auth_data_property_when_cache_exists(self): - self.auth_provider.cache = 'foo' - self.useFixture(mockpatch.PatchObject(self.auth_provider, - 'is_expired', - return_value=False)) - self.assertEqual('foo', getattr(self.auth_provider, 'auth_data')) - - def test_delete_auth_data_property_through_deleter(self): - self.auth_provider.cache = 'foo' - del self.auth_provider.auth_data - self.assertIsNone(self.auth_provider.cache) - - def test_delete_auth_data_property_through_clear_auth(self): - self.auth_provider.cache = 'foo' - self.auth_provider.clear_auth() - self.assertIsNone(self.auth_provider.cache) - - def test_set_and_reset_alt_auth_data(self): - self.auth_provider.set_alt_auth_data('foo', 'bar') - self.assertEqual(self.auth_provider.alt_part, 'foo') - self.assertEqual(self.auth_provider.alt_auth_data, 'bar') - - self.auth_provider.reset_alt_auth_data() - self.assertIsNone(self.auth_provider.alt_part) - self.assertIsNone(self.auth_provider.alt_auth_data) - - def test_auth_class(self): - self.assertRaises(TypeError, - auth.AuthProvider, - fake_credentials.FakeCredentials) - - -class TestKeystoneV2AuthProvider(BaseAuthTestsSetUp): - _endpoints = fake_identity.IDENTITY_V2_RESPONSE['access']['serviceCatalog'] - _auth_provider_class = auth.KeystoneV2AuthProvider - credentials = fake_credentials.FakeKeystoneV2Credentials() - - def setUp(self): - super(TestKeystoneV2AuthProvider, self).setUp() - self.stubs.Set(v2_client.TokenClient, 'raw_request', - fake_identity._fake_v2_response) - self.target_url = 'test_api' - - def _get_fake_identity(self): - return fake_identity.IDENTITY_V2_RESPONSE['access'] - - def _get_fake_alt_identity(self): - return fake_identity.ALT_IDENTITY_V2_RESPONSE['access'] - - def _get_result_url_from_endpoint(self, ep, endpoint_type='publicURL', - replacement=None): - if replacement: - return ep[endpoint_type].replace('v2', replacement) - return ep[endpoint_type] - - def _get_token_from_fake_identity(self): - return fake_identity.TOKEN - - def _get_from_fake_identity(self, attr): - access = fake_identity.IDENTITY_V2_RESPONSE['access'] - if attr == 'user_id': - return access['user']['id'] - elif attr == 'tenant_id': - return access['token']['tenant']['id'] - - def _test_request_helper(self, filters, expected): - url, headers, body = self.auth_provider.auth_request('GET', - self.target_url, - filters=filters) - - self.assertEqual(expected['url'], url) - self.assertEqual(expected['token'], headers['X-Auth-Token']) - self.assertEqual(expected['body'], body) - - def _auth_data_with_expiry(self, date_as_string): - token, access = self.auth_provider.auth_data - access['token']['expires'] = date_as_string - return token, access - - def test_request(self): - filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'FakeRegion' - } - - url = self._get_result_url_from_endpoint( - self._endpoints[0]['endpoints'][1]) + '/' + self.target_url - - expected = { - 'body': None, - 'url': url, - 'token': self._get_token_from_fake_identity(), - } - self._test_request_helper(filters, expected) - - def test_request_with_alt_auth_cleans_alt(self): - """Test alternate auth data for headers - - Assert that when the alt data is provided for headers, after an - auth_request the data alt_data is cleaned-up. - """ - self.auth_provider.set_alt_auth_data( - 'headers', - (fake_identity.ALT_TOKEN, self._get_fake_alt_identity())) - filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'fakeRegion' - } - self.auth_provider.auth_request('GET', self.target_url, - filters=filters) - - # Assert alt auth data is clear after it - self.assertIsNone(self.auth_provider.alt_part) - self.assertIsNone(self.auth_provider.alt_auth_data) - - def _test_request_with_identical_alt_auth(self, part): - """Test alternate but identical auth data for headers - - Assert that when the alt data is provided, but it's actually - identical, an exception is raised. - """ - self.auth_provider.set_alt_auth_data( - part, - (fake_identity.TOKEN, self._get_fake_identity())) - filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'fakeRegion' - } - - self.assertRaises(exceptions.BadAltAuth, - self.auth_provider.auth_request, - 'GET', self.target_url, filters=filters) - - def test_request_with_identical_alt_auth_headers(self): - self._test_request_with_identical_alt_auth('headers') - - def test_request_with_identical_alt_auth_url(self): - self._test_request_with_identical_alt_auth('url') - - def test_request_with_identical_alt_auth_body(self): - self._test_request_with_identical_alt_auth('body') - - def test_request_with_alt_part_without_alt_data(self): - """Test empty alternate auth data - - Assert that when alt_part is defined, the corresponding original - request element is kept the same. - """ - filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'fakeRegion' - } - self.auth_provider.set_alt_auth_data('headers', None) - - url, headers, body = self.auth_provider.auth_request('GET', - self.target_url, - filters=filters) - # The original headers where empty - self.assertNotEqual(url, self.target_url) - self.assertIsNone(headers) - self.assertEqual(body, None) - - def _test_request_with_alt_part_without_alt_data_no_change(self, body): - """Test empty alternate auth data with no effect - - Assert that when alt_part is defined, no auth_data is provided, - and the the corresponding original request element was not going to - be changed anyways, and exception is raised - """ - filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'fakeRegion' - } - self.auth_provider.set_alt_auth_data('body', None) - - self.assertRaises(exceptions.BadAltAuth, - self.auth_provider.auth_request, - 'GET', self.target_url, filters=filters) - - def test_request_with_alt_part_without_alt_data_no_change_headers(self): - self._test_request_with_alt_part_without_alt_data_no_change('headers') - - def test_request_with_alt_part_without_alt_data_no_change_url(self): - self._test_request_with_alt_part_without_alt_data_no_change('url') - - def test_request_with_alt_part_without_alt_data_no_change_body(self): - self._test_request_with_alt_part_without_alt_data_no_change('body') - - def test_request_with_bad_service(self): - filters = { - 'service': 'BAD_SERVICE', - 'endpoint_type': 'publicURL', - 'region': 'fakeRegion' - } - self.assertRaises(exceptions.EndpointNotFound, - self.auth_provider.auth_request, 'GET', - self.target_url, filters=filters) - - def test_request_without_service(self): - filters = { - 'service': None, - 'endpoint_type': 'publicURL', - 'region': 'fakeRegion' - } - self.assertRaises(exceptions.EndpointNotFound, - self.auth_provider.auth_request, 'GET', - self.target_url, filters=filters) - - def test_check_credentials_missing_attribute(self): - for attr in ['username', 'password']: - cred = copy.copy(self.credentials) - del cred[attr] - self.assertFalse(self.auth_provider.check_credentials(cred)) - - def test_fill_credentials(self): - self.auth_provider.fill_credentials() - creds = self.auth_provider.credentials - for attr in ['user_id', 'tenant_id']: - self.assertEqual(self._get_from_fake_identity(attr), - getattr(creds, attr)) - - def _test_base_url_helper(self, expected_url, filters, - auth_data=None): - - url = self.auth_provider.base_url(filters, auth_data) - self.assertEqual(url, expected_url) - - def test_base_url(self): - self.filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'FakeRegion' - } - expected = self._get_result_url_from_endpoint( - self._endpoints[0]['endpoints'][1]) - self._test_base_url_helper(expected, self.filters) - - def test_base_url_to_get_admin_endpoint(self): - self.filters = { - 'service': 'compute', - 'endpoint_type': 'adminURL', - 'region': 'FakeRegion' - } - expected = self._get_result_url_from_endpoint( - self._endpoints[0]['endpoints'][1], endpoint_type='adminURL') - self._test_base_url_helper(expected, self.filters) - - def test_base_url_unknown_region(self): - """If the region is unknown, the first endpoint is returned.""" - self.filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'AintNoBodyKnowThisRegion' - } - expected = self._get_result_url_from_endpoint( - self._endpoints[0]['endpoints'][0]) - self._test_base_url_helper(expected, self.filters) - - def test_base_url_with_non_existent_service(self): - self.filters = { - 'service': 'BAD_SERVICE', - 'endpoint_type': 'publicURL', - 'region': 'FakeRegion' - } - self.assertRaises(exceptions.EndpointNotFound, - self._test_base_url_helper, None, self.filters) - - def test_base_url_without_service(self): - self.filters = { - 'endpoint_type': 'publicURL', - 'region': 'FakeRegion' - } - self.assertRaises(exceptions.EndpointNotFound, - self._test_base_url_helper, None, self.filters) - - def test_base_url_with_api_version_filter(self): - self.filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'FakeRegion', - 'api_version': 'v12' - } - expected = self._get_result_url_from_endpoint( - self._endpoints[0]['endpoints'][1], replacement='v12') - self._test_base_url_helper(expected, self.filters) - - def test_base_url_with_skip_path_filter(self): - self.filters = { - 'service': 'compute', - 'endpoint_type': 'publicURL', - 'region': 'FakeRegion', - 'skip_path': True - } - expected = 'http://fake_url/' - self._test_base_url_helper(expected, self.filters) - - def test_token_not_expired(self): - expiry_data = datetime.datetime.utcnow() + datetime.timedelta(days=1) - self._verify_expiry(expiry_data=expiry_data, should_be_expired=False) - - def test_token_expired(self): - expiry_data = datetime.datetime.utcnow() - datetime.timedelta(hours=1) - self._verify_expiry(expiry_data=expiry_data, should_be_expired=True) - - def test_token_not_expired_to_be_renewed(self): - expiry_data = (datetime.datetime.utcnow() + - self.auth_provider.token_expiry_threshold / 2) - self._verify_expiry(expiry_data=expiry_data, should_be_expired=True) - - def _verify_expiry(self, expiry_data, should_be_expired): - for expiry_format in self.auth_provider.EXPIRY_DATE_FORMATS: - auth_data = self._auth_data_with_expiry( - expiry_data.strftime(expiry_format)) - self.assertEqual(self.auth_provider.is_expired(auth_data), - should_be_expired) - - -class TestKeystoneV3AuthProvider(TestKeystoneV2AuthProvider): - _endpoints = fake_identity.IDENTITY_V3_RESPONSE['token']['catalog'] - _auth_provider_class = auth.KeystoneV3AuthProvider - credentials = fake_credentials.FakeKeystoneV3Credentials() - - def setUp(self): - super(TestKeystoneV3AuthProvider, self).setUp() - self.stubs.Set(v3_client.V3TokenClient, 'raw_request', - fake_identity._fake_v3_response) - - def _get_fake_identity(self): - return fake_identity.IDENTITY_V3_RESPONSE['token'] - - def _get_fake_alt_identity(self): - return fake_identity.ALT_IDENTITY_V3['token'] - - def _get_result_url_from_endpoint(self, ep, replacement=None): - if replacement: - return ep['url'].replace('v3', replacement) - return ep['url'] - - def _auth_data_with_expiry(self, date_as_string): - token, access = self.auth_provider.auth_data - access['expires_at'] = date_as_string - return token, access - - def _get_from_fake_identity(self, attr): - token = fake_identity.IDENTITY_V3_RESPONSE['token'] - if attr == 'user_id': - return token['user']['id'] - elif attr == 'project_id': - return token['project']['id'] - elif attr == 'user_domain_id': - return token['user']['domain']['id'] - elif attr == 'project_domain_id': - return token['project']['domain']['id'] - - def test_check_credentials_missing_attribute(self): - # reset credentials to fresh ones - self.credentials.reset() - for attr in ['username', 'password', 'user_domain_name', - 'project_domain_name']: - cred = copy.copy(self.credentials) - del cred[attr] - self.assertFalse(self.auth_provider.check_credentials(cred), - "Credentials should be invalid without %s" % attr) - - def test_check_domain_credentials_missing_attribute(self): - # reset credentials to fresh ones - self.credentials.reset() - domain_creds = fake_credentials.FakeKeystoneV3DomainCredentials() - for attr in ['username', 'password', 'user_domain_name']: - cred = copy.copy(domain_creds) - del cred[attr] - self.assertFalse(self.auth_provider.check_credentials(cred), - "Credentials should be invalid without %s" % attr) - - def test_fill_credentials(self): - self.auth_provider.fill_credentials() - creds = self.auth_provider.credentials - for attr in ['user_id', 'project_id', 'user_domain_id', - 'project_domain_id']: - self.assertEqual(self._get_from_fake_identity(attr), - getattr(creds, attr)) - - # Overwrites v2 test - def test_base_url_to_get_admin_endpoint(self): - self.filters = { - 'service': 'compute', - 'endpoint_type': 'admin', - 'region': 'MiddleEarthRegion' - } - expected = self._get_result_url_from_endpoint( - self._endpoints[0]['endpoints'][2]) - self._test_base_url_helper(expected, self.filters) diff --git a/tempest_lib/tests/test_base.py b/tempest_lib/tests/test_base.py deleted file mode 100644 index 825327b..0000000 --- a/tempest_lib/tests/test_base.py +++ /dev/null @@ -1,64 +0,0 @@ -# Copyright 2014 Mirantis Inc. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import testtools - -from tempest_lib import base -from tempest_lib import exceptions - - -class TestAttr(base.BaseTestCase): - - def test_has_no_attrs(self): - self.assertEqual( - 'tempest_lib.tests.test_base.TestAttr.test_has_no_attrs', - self.id() - ) - - @testtools.testcase.attr('foo') - def test_has_one_attr(self): - self.assertEqual( - 'tempest_lib.tests.test_base.TestAttr.test_has_one_attr[foo]', - self.id() - ) - - @testtools.testcase.attr('foo') - @testtools.testcase.attr('bar') - def test_has_two_attrs(self): - self.assertEqual( - 'tempest_lib.tests.test_base.TestAttr.test_has_two_attrs[bar,foo]', - self.id(), - ) - - -class TestSetUpClass(base.BaseTestCase): - - @classmethod - def setUpClass(cls): - """Simulate absence of super() call.""" - - def setUp(self): - try: - # We expect here RuntimeError exception because 'setUpClass' - # has not called 'super'. - super(TestSetUpClass, self).setUp() - except RuntimeError: - pass - else: - raise exceptions.TempestException( - "If you see this, then expected exception was not raised.") - - def test_setup_class_raises_runtime_error(self): - """No-op test just to call setUp.""" diff --git a/tempest_lib/tests/test_credentials.py b/tempest_lib/tests/test_credentials.py deleted file mode 100644 index f0ebf25..0000000 --- a/tempest_lib/tests/test_credentials.py +++ /dev/null @@ -1,180 +0,0 @@ -# Copyright 2014 Hewlett-Packard Development Company, L.P. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy - -from tempest_lib import auth -from tempest_lib import exceptions -from tempest_lib.services.identity.v2 import token_client as v2_client -from tempest_lib.services.identity.v3 import token_client as v3_client -from tempest_lib.tests import base -from tempest_lib.tests import fake_identity - - -class CredentialsTests(base.TestCase): - attributes = {} - credentials_class = auth.Credentials - - def _get_credentials(self, attributes=None): - if attributes is None: - attributes = self.attributes - return self.credentials_class(**attributes) - - def _check(self, credentials, credentials_class, filled): - # Check the right version of credentials has been returned - self.assertIsInstance(credentials, credentials_class) - # Check the id attributes are filled in - attributes = [x for x in credentials.ATTRIBUTES if ( - '_id' in x and x != 'domain_id')] - for attr in attributes: - if filled: - self.assertIsNotNone(getattr(credentials, attr)) - else: - self.assertIsNone(getattr(credentials, attr)) - - def test_create(self): - creds = self._get_credentials() - self.assertEqual(self.attributes, creds._initial) - - def test_create_invalid_attr(self): - self.assertRaises(exceptions.InvalidCredentials, - self._get_credentials, - attributes=dict(invalid='fake')) - - def test_is_valid(self): - creds = self._get_credentials() - self.assertRaises(NotImplementedError, creds.is_valid) - - -class KeystoneV2CredentialsTests(CredentialsTests): - attributes = { - 'username': 'fake_username', - 'password': 'fake_password', - 'tenant_name': 'fake_tenant_name' - } - - identity_response = fake_identity._fake_v2_response - credentials_class = auth.KeystoneV2Credentials - tokenclient_class = v2_client.TokenClient - identity_version = 'v2' - - def setUp(self): - super(KeystoneV2CredentialsTests, self).setUp() - self.stubs.Set(self.tokenclient_class, 'raw_request', - self.identity_response) - - def _verify_credentials(self, credentials_class, creds_dict, filled=True): - creds = auth.get_credentials(fake_identity.FAKE_AUTH_URL, - fill_in=filled, - identity_version=self.identity_version, - **creds_dict) - self._check(creds, credentials_class, filled) - - def test_get_credentials(self): - self._verify_credentials(credentials_class=self.credentials_class, - creds_dict=self.attributes) - - def test_get_credentials_not_filled(self): - self._verify_credentials(credentials_class=self.credentials_class, - creds_dict=self.attributes, - filled=False) - - def test_is_valid(self): - creds = self._get_credentials() - self.assertTrue(creds.is_valid()) - - def _test_is_not_valid(self, ignore_key): - creds = self._get_credentials() - for attr in self.attributes.keys(): - if attr == ignore_key: - continue - temp_attr = getattr(creds, attr) - delattr(creds, attr) - self.assertFalse(creds.is_valid(), - "Credentials should be invalid without %s" % attr) - setattr(creds, attr, temp_attr) - - def test_is_not_valid(self): - # NOTE(mtreinish): A KeystoneV2 credential object is valid without - # a tenant_name. So skip that check. See tempest.auth for the valid - # credential requirements - self._test_is_not_valid('tenant_name') - - def test_reset_all_attributes(self): - creds = self._get_credentials() - initial_creds = copy.deepcopy(creds) - set_attr = creds.__dict__.keys() - missing_attr = set(creds.ATTRIBUTES).difference(set_attr) - # Set all unset attributes, then reset - for attr in missing_attr: - setattr(creds, attr, 'fake' + attr) - creds.reset() - # Check reset credentials are same as initial ones - self.assertEqual(creds, initial_creds) - - def test_reset_single_attribute(self): - creds = self._get_credentials() - initial_creds = copy.deepcopy(creds) - set_attr = creds.__dict__.keys() - missing_attr = set(creds.ATTRIBUTES).difference(set_attr) - # Set one unset attributes, then reset - for attr in missing_attr: - setattr(creds, attr, 'fake' + attr) - creds.reset() - # Check reset credentials are same as initial ones - self.assertEqual(creds, initial_creds) - - -class KeystoneV3CredentialsTests(KeystoneV2CredentialsTests): - attributes = { - 'username': 'fake_username', - 'password': 'fake_password', - 'project_name': 'fake_project_name', - 'user_domain_name': 'fake_domain_name' - } - - credentials_class = auth.KeystoneV3Credentials - identity_response = fake_identity._fake_v3_response - tokenclient_class = v3_client.V3TokenClient - identity_version = 'v3' - - def test_is_not_valid(self): - # NOTE(mtreinish) For a Keystone V3 credential object a project name - # is not required to be valid, so we skip that check. See tempest.auth - # for the valid credential requirements - self._test_is_not_valid('project_name') - - def test_synced_attributes(self): - attributes = self.attributes - # Create V3 credentials with tenant instead of project, and user_domain - for attr in ['project_id', 'user_domain_id']: - attributes[attr] = 'fake_' + attr - creds = self._get_credentials(attributes) - self.assertEqual(creds.project_name, creds.tenant_name) - self.assertEqual(creds.project_id, creds.tenant_id) - self.assertEqual(creds.user_domain_name, creds.project_domain_name) - self.assertEqual(creds.user_domain_id, creds.project_domain_id) - # Replace user_domain with project_domain - del attributes['user_domain_name'] - del attributes['user_domain_id'] - del attributes['project_name'] - del attributes['project_id'] - for attr in ['project_domain_name', 'project_domain_id', - 'tenant_name', 'tenant_id']: - attributes[attr] = 'fake_' + attr - self.assertEqual(creds.tenant_name, creds.project_name) - self.assertEqual(creds.tenant_id, creds.project_id) - self.assertEqual(creds.project_domain_name, creds.user_domain_name) - self.assertEqual(creds.project_domain_id, creds.user_domain_id) diff --git a/tempest_lib/tests/test_decorators.py b/tempest_lib/tests/test_decorators.py deleted file mode 100644 index 252e009..0000000 --- a/tempest_lib/tests/test_decorators.py +++ /dev/null @@ -1,126 +0,0 @@ -# Copyright 2013 IBM Corp -# Copyright 2015 Hewlett-Packard Development Company, L.P. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import uuid - -import testtools - -from tempest_lib import base as test -from tempest_lib import decorators -from tempest_lib.tests import base - - -class TestSkipBecauseDecorator(base.TestCase): - def _test_skip_because_helper(self, expected_to_skip=True, - **decorator_args): - class TestFoo(test.BaseTestCase): - _interface = 'json' - - @decorators.skip_because(**decorator_args) - def test_bar(self): - return 0 - - t = TestFoo('test_bar') - if expected_to_skip: - self.assertRaises(testtools.TestCase.skipException, t.test_bar) - else: - # assert that test_bar returned 0 - self.assertEqual(TestFoo('test_bar').test_bar(), 0) - - def test_skip_because_bug(self): - self._test_skip_because_helper(bug='12345') - - def test_skip_because_bug_and_condition_true(self): - self._test_skip_because_helper(bug='12348', condition=True) - - def test_skip_because_bug_and_condition_false(self): - self._test_skip_because_helper(expected_to_skip=False, - bug='12349', condition=False) - - def test_skip_because_bug_without_bug_never_skips(self): - """Never skip without a bug parameter.""" - self._test_skip_because_helper(expected_to_skip=False, - condition=True) - self._test_skip_because_helper(expected_to_skip=False) - - def test_skip_because_invalid_bug_number(self): - """Raise ValueError if with an invalid bug number""" - self.assertRaises(ValueError, self._test_skip_because_helper, - bug='critical_bug') - - -class TestIdempotentIdDecorator(base.TestCase): - def _test_helper(self, _id, **decorator_args): - @decorators.idempotent_id(_id) - def foo(): - """Docstring""" - pass - - return foo - - def _test_helper_without_doc(self, _id, **decorator_args): - @decorators.idempotent_id(_id) - def foo(): - pass - - return foo - - def test_positive(self): - _id = str(uuid.uuid4()) - foo = self._test_helper(_id) - self.assertIn('id-%s' % _id, getattr(foo, '__testtools_attrs')) - self.assertTrue(foo.__doc__.startswith('Test idempotent id: %s' % _id)) - - def test_positive_without_doc(self): - _id = str(uuid.uuid4()) - foo = self._test_helper_without_doc(_id) - self.assertTrue(foo.__doc__.startswith('Test idempotent id: %s' % _id)) - - def test_idempotent_id_not_str(self): - _id = 42 - self.assertRaises(TypeError, self._test_helper, _id) - - def test_idempotent_id_not_valid_uuid(self): - _id = '42' - self.assertRaises(ValueError, self._test_helper, _id) - - -class TestSkipUnlessAttrDecorator(base.TestCase): - def _test_skip_unless_attr(self, attr, expected_to_skip=True): - class TestFoo(test.BaseTestCase): - expected_attr = not expected_to_skip - - @decorators.skip_unless_attr(attr) - def test_foo(self): - pass - - t = TestFoo('test_foo') - if expected_to_skip: - self.assertRaises(testtools.TestCase.skipException, - t.test_foo()) - else: - try: - t.test_foo() - except Exception: - raise testtools.TestCase.failureException() - - def test_skip_attr_does_not_exist(self): - self._test_skip_unless_attr('unexpected_attr') - - def test_skip_attr_false(self): - self._test_skip_unless_attr('expected_attr') - - def test_no_skip_for_attr_exist_and_true(self): - self._test_skip_unless_attr('expected_attr', expected_to_skip=False) diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py deleted file mode 100644 index 452cef5..0000000 --- a/tempest_lib/tests/test_rest_client.py +++ /dev/null @@ -1,1065 +0,0 @@ -# Copyright 2013 IBM Corp. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import copy -import json - -import httplib2 -import jsonschema -from oslotest import mockpatch -import six - -from tempest_lib.common import rest_client -from tempest_lib import exceptions -from tempest_lib.tests import base -from tempest_lib.tests import fake_auth_provider -from tempest_lib.tests import fake_http - - -class BaseRestClientTestClass(base.TestCase): - - url = 'fake_endpoint' - - def setUp(self): - super(BaseRestClientTestClass, self).setUp() - self.fake_auth_provider = fake_auth_provider.FakeAuthProvider() - self.rest_client = rest_client.RestClient( - self.fake_auth_provider, None, None) - self.stubs.Set(httplib2.Http, 'request', self.fake_http.request) - self.useFixture(mockpatch.PatchObject(self.rest_client, - '_log_request')) - - -class TestRestClientHTTPMethods(BaseRestClientTestClass): - def setUp(self): - self.fake_http = fake_http.fake_httplib2() - super(TestRestClientHTTPMethods, self).setUp() - self.useFixture(mockpatch.PatchObject(self.rest_client, - '_error_checker')) - - def test_post(self): - __, return_dict = self.rest_client.post(self.url, {}, {}) - self.assertEqual('POST', return_dict['method']) - - def test_get(self): - __, return_dict = self.rest_client.get(self.url) - self.assertEqual('GET', return_dict['method']) - - def test_delete(self): - __, return_dict = self.rest_client.delete(self.url) - self.assertEqual('DELETE', return_dict['method']) - - def test_patch(self): - __, return_dict = self.rest_client.patch(self.url, {}, {}) - self.assertEqual('PATCH', return_dict['method']) - - def test_put(self): - __, return_dict = self.rest_client.put(self.url, {}, {}) - self.assertEqual('PUT', return_dict['method']) - - def test_head(self): - self.useFixture(mockpatch.PatchObject(self.rest_client, - 'response_checker')) - __, return_dict = self.rest_client.head(self.url) - self.assertEqual('HEAD', return_dict['method']) - - def test_copy(self): - __, return_dict = self.rest_client.copy(self.url) - self.assertEqual('COPY', return_dict['method']) - - -class TestRestClientNotFoundHandling(BaseRestClientTestClass): - def setUp(self): - self.fake_http = fake_http.fake_httplib2(404) - super(TestRestClientNotFoundHandling, self).setUp() - - def test_post(self): - self.assertRaises(exceptions.NotFound, self.rest_client.post, - self.url, {}, {}) - - -class TestRestClientHeadersJSON(TestRestClientHTTPMethods): - TYPE = "json" - - def _verify_headers(self, resp): - self.assertEqual(self.rest_client._get_type(), self.TYPE) - resp = dict((k.lower(), v) for k, v in six.iteritems(resp)) - self.assertEqual(self.header_value, resp['accept']) - self.assertEqual(self.header_value, resp['content-type']) - - def setUp(self): - super(TestRestClientHeadersJSON, self).setUp() - self.rest_client.TYPE = self.TYPE - self.header_value = 'application/%s' % self.rest_client._get_type() - - def test_post(self): - resp, __ = self.rest_client.post(self.url, {}) - self._verify_headers(resp) - - def test_get(self): - resp, __ = self.rest_client.get(self.url) - self._verify_headers(resp) - - def test_delete(self): - resp, __ = self.rest_client.delete(self.url) - self._verify_headers(resp) - - def test_patch(self): - resp, __ = self.rest_client.patch(self.url, {}) - self._verify_headers(resp) - - def test_put(self): - resp, __ = self.rest_client.put(self.url, {}) - self._verify_headers(resp) - - def test_head(self): - self.useFixture(mockpatch.PatchObject(self.rest_client, - 'response_checker')) - resp, __ = self.rest_client.head(self.url) - self._verify_headers(resp) - - def test_copy(self): - resp, __ = self.rest_client.copy(self.url) - self._verify_headers(resp) - - -class TestRestClientUpdateHeaders(BaseRestClientTestClass): - def setUp(self): - self.fake_http = fake_http.fake_httplib2() - super(TestRestClientUpdateHeaders, self).setUp() - self.useFixture(mockpatch.PatchObject(self.rest_client, - '_error_checker')) - self.headers = {'X-Configuration-Session': 'session_id'} - - def test_post_update_headers(self): - __, return_dict = self.rest_client.post(self.url, {}, - extra_headers=True, - headers=self.headers) - - self.assertDictContainsSubset( - {'X-Configuration-Session': 'session_id', - 'Content-Type': 'application/json', - 'Accept': 'application/json'}, - return_dict['headers'] - ) - - def test_get_update_headers(self): - __, return_dict = self.rest_client.get(self.url, - extra_headers=True, - headers=self.headers) - - self.assertDictContainsSubset( - {'X-Configuration-Session': 'session_id', - 'Content-Type': 'application/json', - 'Accept': 'application/json'}, - return_dict['headers'] - ) - - def test_delete_update_headers(self): - __, return_dict = self.rest_client.delete(self.url, - extra_headers=True, - headers=self.headers) - - self.assertDictContainsSubset( - {'X-Configuration-Session': 'session_id', - 'Content-Type': 'application/json', - 'Accept': 'application/json'}, - return_dict['headers'] - ) - - def test_patch_update_headers(self): - __, return_dict = self.rest_client.patch(self.url, {}, - extra_headers=True, - headers=self.headers) - - self.assertDictContainsSubset( - {'X-Configuration-Session': 'session_id', - 'Content-Type': 'application/json', - 'Accept': 'application/json'}, - return_dict['headers'] - ) - - def test_put_update_headers(self): - __, return_dict = self.rest_client.put(self.url, {}, - extra_headers=True, - headers=self.headers) - - self.assertDictContainsSubset( - {'X-Configuration-Session': 'session_id', - 'Content-Type': 'application/json', - 'Accept': 'application/json'}, - return_dict['headers'] - ) - - def test_head_update_headers(self): - self.useFixture(mockpatch.PatchObject(self.rest_client, - 'response_checker')) - - __, return_dict = self.rest_client.head(self.url, - extra_headers=True, - headers=self.headers) - - self.assertDictContainsSubset( - {'X-Configuration-Session': 'session_id', - 'Content-Type': 'application/json', - 'Accept': 'application/json'}, - return_dict['headers'] - ) - - def test_copy_update_headers(self): - __, return_dict = self.rest_client.copy(self.url, - extra_headers=True, - headers=self.headers) - - self.assertDictContainsSubset( - {'X-Configuration-Session': 'session_id', - 'Content-Type': 'application/json', - 'Accept': 'application/json'}, - return_dict['headers'] - ) - - -class TestRestClientParseRespJSON(BaseRestClientTestClass): - TYPE = "json" - - keys = ["fake_key1", "fake_key2"] - values = ["fake_value1", "fake_value2"] - item_expected = dict((key, value) for (key, value) in zip(keys, values)) - list_expected = {"body_list": [ - {keys[0]: values[0]}, - {keys[1]: values[1]}, - ]} - dict_expected = {"body_dict": { - keys[0]: values[0], - keys[1]: values[1], - }} - null_dict = {} - - def setUp(self): - self.fake_http = fake_http.fake_httplib2() - super(TestRestClientParseRespJSON, self).setUp() - self.rest_client.TYPE = self.TYPE - - def test_parse_resp_body_item(self): - body = self.rest_client._parse_resp(json.dumps(self.item_expected)) - self.assertEqual(self.item_expected, body) - - def test_parse_resp_body_list(self): - body = self.rest_client._parse_resp(json.dumps(self.list_expected)) - self.assertEqual(self.list_expected["body_list"], body) - - def test_parse_resp_body_dict(self): - body = self.rest_client._parse_resp(json.dumps(self.dict_expected)) - self.assertEqual(self.dict_expected["body_dict"], body) - - def test_parse_resp_two_top_keys(self): - dict_two_keys = self.dict_expected.copy() - dict_two_keys.update({"second_key": ""}) - body = self.rest_client._parse_resp(json.dumps(dict_two_keys)) - self.assertEqual(dict_two_keys, body) - - def test_parse_resp_one_top_key_without_list_or_dict(self): - data = {"one_top_key": "not_list_or_dict_value"} - body = self.rest_client._parse_resp(json.dumps(data)) - self.assertEqual(data, body) - - def test_parse_nullable_dict(self): - body = self.rest_client._parse_resp(json.dumps(self.null_dict)) - self.assertEqual(self.null_dict, body) - - -class TestRestClientErrorCheckerJSON(base.TestCase): - c_type = "application/json" - - def set_data(self, r_code, enc=None, r_body=None, absolute_limit=True): - if enc is None: - enc = self.c_type - resp_dict = {'status': r_code, 'content-type': enc} - resp_body = {'resp_body': 'fake_resp_body'} - - if absolute_limit is False: - resp_dict.update({'retry-after': 120}) - resp_body.update({'overLimit': {'message': 'fake_message'}}) - resp = httplib2.Response(resp_dict) - data = { - "method": "fake_method", - "url": "fake_url", - "headers": "fake_headers", - "body": "fake_body", - "resp": resp, - "resp_body": json.dumps(resp_body) - } - if r_body is not None: - data.update({"resp_body": r_body}) - return data - - def setUp(self): - super(TestRestClientErrorCheckerJSON, self).setUp() - self.rest_client = rest_client.RestClient( - fake_auth_provider.FakeAuthProvider(), None, None) - - def test_response_less_than_400(self): - self.rest_client._error_checker(**self.set_data("399")) - - def _test_error_checker(self, exception_type, data): - e = self.assertRaises(exception_type, - self.rest_client._error_checker, - **data) - self.assertEqual(e.resp, data['resp']) - self.assertTrue(hasattr(e, 'resp_body')) - return e - - def test_response_400(self): - self._test_error_checker(exceptions.BadRequest, self.set_data("400")) - - def test_response_401(self): - self._test_error_checker(exceptions.Unauthorized, self.set_data("401")) - - def test_response_403(self): - self._test_error_checker(exceptions.Forbidden, self.set_data("403")) - - def test_response_404(self): - self._test_error_checker(exceptions.NotFound, self.set_data("404")) - - def test_response_409(self): - self._test_error_checker(exceptions.Conflict, self.set_data("409")) - - def test_response_410(self): - self._test_error_checker(exceptions.Gone, self.set_data("410")) - - def test_response_413(self): - self._test_error_checker(exceptions.OverLimit, self.set_data("413")) - - def test_response_413_without_absolute_limit(self): - self._test_error_checker(exceptions.RateLimitExceeded, - self.set_data("413", absolute_limit=False)) - - def test_response_415(self): - self._test_error_checker(exceptions.InvalidContentType, - self.set_data("415")) - - def test_response_422(self): - self._test_error_checker(exceptions.UnprocessableEntity, - self.set_data("422")) - - def test_response_500_with_text(self): - # _parse_resp is expected to return 'str' - self._test_error_checker(exceptions.ServerFault, self.set_data("500")) - - def test_response_501_with_text(self): - self._test_error_checker(exceptions.NotImplemented, - self.set_data("501")) - - def test_response_400_with_dict(self): - r_body = '{"resp_body": {"err": "fake_resp_body"}}' - e = self._test_error_checker(exceptions.BadRequest, - self.set_data("400", r_body=r_body)) - - if self.c_type == 'application/json': - expected = {"err": "fake_resp_body"} - else: - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_401_with_dict(self): - r_body = '{"resp_body": {"err": "fake_resp_body"}}' - e = self._test_error_checker(exceptions.Unauthorized, - self.set_data("401", r_body=r_body)) - - if self.c_type == 'application/json': - expected = {"err": "fake_resp_body"} - else: - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_403_with_dict(self): - r_body = '{"resp_body": {"err": "fake_resp_body"}}' - e = self._test_error_checker(exceptions.Forbidden, - self.set_data("403", r_body=r_body)) - - if self.c_type == 'application/json': - expected = {"err": "fake_resp_body"} - else: - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_404_with_dict(self): - r_body = '{"resp_body": {"err": "fake_resp_body"}}' - e = self._test_error_checker(exceptions.NotFound, - self.set_data("404", r_body=r_body)) - - if self.c_type == 'application/json': - expected = {"err": "fake_resp_body"} - else: - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_404_with_invalid_dict(self): - r_body = '{"foo": "bar"]' - e = self._test_error_checker(exceptions.NotFound, - self.set_data("404", r_body=r_body)) - - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_410_with_dict(self): - r_body = '{"resp_body": {"err": "fake_resp_body"}}' - e = self._test_error_checker(exceptions.Gone, - self.set_data("410", r_body=r_body)) - - if self.c_type == 'application/json': - expected = {"err": "fake_resp_body"} - else: - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_410_with_invalid_dict(self): - r_body = '{"foo": "bar"]' - e = self._test_error_checker(exceptions.Gone, - self.set_data("410", r_body=r_body)) - - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_409_with_dict(self): - r_body = '{"resp_body": {"err": "fake_resp_body"}}' - e = self._test_error_checker(exceptions.Conflict, - self.set_data("409", r_body=r_body)) - - if self.c_type == 'application/json': - expected = {"err": "fake_resp_body"} - else: - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_500_with_dict(self): - r_body = '{"resp_body": {"err": "fake_resp_body"}}' - e = self._test_error_checker(exceptions.ServerFault, - self.set_data("500", r_body=r_body)) - - if self.c_type == 'application/json': - expected = {"err": "fake_resp_body"} - else: - expected = r_body - self.assertEqual(expected, e.resp_body) - - def test_response_501_with_dict(self): - r_body = '{"resp_body": {"err": "fake_resp_body"}}' - self._test_error_checker(exceptions.NotImplemented, - self.set_data("501", r_body=r_body)) - - def test_response_bigger_than_400(self): - # Any response code, that bigger than 400, and not in - # (401, 403, 404, 409, 413, 422, 500, 501) - self._test_error_checker(exceptions.UnexpectedResponseCode, - self.set_data("402")) - - -class TestRestClientErrorCheckerTEXT(TestRestClientErrorCheckerJSON): - c_type = "text/plain" - - def test_fake_content_type(self): - # This test is required only in one exemplar - # Any response code, that bigger than 400, and not in - # (401, 403, 404, 409, 413, 422, 500, 501) - self._test_error_checker(exceptions.UnexpectedContentType, - self.set_data("405", enc="fake_enc")) - - def test_response_413_without_absolute_limit(self): - # Skip this test because rest_client cannot get overLimit message - # from text body. - pass - - -class TestRestClientUtils(BaseRestClientTestClass): - - def _is_resource_deleted(self, resource_id): - if not isinstance(self.retry_pass, int): - return False - if self.retry_count >= self.retry_pass: - return True - self.retry_count = self.retry_count + 1 - return False - - def setUp(self): - self.fake_http = fake_http.fake_httplib2() - super(TestRestClientUtils, self).setUp() - self.retry_count = 0 - self.retry_pass = None - self.original_deleted_method = self.rest_client.is_resource_deleted - self.rest_client.is_resource_deleted = self._is_resource_deleted - - def test_wait_for_resource_deletion(self): - self.retry_pass = 2 - # Ensure timeout long enough for loop execution to hit retry count - self.rest_client.build_timeout = 500 - sleep_mock = self.patch('time.sleep') - self.rest_client.wait_for_resource_deletion('1234') - self.assertEqual(len(sleep_mock.mock_calls), 2) - - def test_wait_for_resource_deletion_not_deleted(self): - self.patch('time.sleep') - # Set timeout to be very quick to force exception faster - self.rest_client.build_timeout = 1 - self.assertRaises(exceptions.TimeoutException, - self.rest_client.wait_for_resource_deletion, - '1234') - - def test_wait_for_deletion_with_unimplemented_deleted_method(self): - self.rest_client.is_resource_deleted = self.original_deleted_method - self.assertRaises(NotImplementedError, - self.rest_client.wait_for_resource_deletion, - '1234') - - def test_get_versions(self): - self.rest_client._parse_resp = lambda x: [{'id': 'v1'}, {'id': 'v2'}] - actual_resp, actual_versions = self.rest_client.get_versions() - self.assertEqual(['v1', 'v2'], list(actual_versions)) - - def test__str__(self): - def get_token(): - return "deadbeef" - - self.fake_auth_provider.get_token = get_token - self.assertIsNotNone(str(self.rest_client)) - - -class TestProperties(BaseRestClientTestClass): - - def setUp(self): - self.fake_http = fake_http.fake_httplib2() - super(TestProperties, self).setUp() - creds_dict = { - 'username': 'test-user', - 'user_id': 'test-user_id', - 'tenant_name': 'test-tenant_name', - 'tenant_id': 'test-tenant_id', - 'password': 'test-password' - } - self.rest_client = rest_client.RestClient( - fake_auth_provider.FakeAuthProvider(creds_dict=creds_dict), - None, None) - - def test_properties(self): - self.assertEqual('test-user', self.rest_client.user) - self.assertEqual('test-user_id', self.rest_client.user_id) - self.assertEqual('test-tenant_name', self.rest_client.tenant_name) - self.assertEqual('test-tenant_id', self.rest_client.tenant_id) - self.assertEqual('test-password', self.rest_client.password) - - self.rest_client.api_version = 'v1' - expected = {'api_version': 'v1', - 'endpoint_type': 'publicURL', - 'region': None, - 'service': None, - 'skip_path': True} - self.rest_client.skip_path() - self.assertEqual(expected, self.rest_client.filters) - - self.rest_client.reset_path() - self.rest_client.api_version = 'v1' - expected = {'api_version': 'v1', - 'endpoint_type': 'publicURL', - 'region': None, - 'service': None} - self.assertEqual(expected, self.rest_client.filters) - - -class TestExpectedSuccess(BaseRestClientTestClass): - - def setUp(self): - self.fake_http = fake_http.fake_httplib2() - super(TestExpectedSuccess, self).setUp() - - def test_expected_succes_int_match(self): - expected_code = 202 - read_code = 202 - resp = self.rest_client.expected_success(expected_code, read_code) - # Assert None resp on success - self.assertFalse(resp) - - def test_expected_succes_int_no_match(self): - expected_code = 204 - read_code = 202 - self.assertRaises(exceptions.InvalidHttpSuccessCode, - self.rest_client.expected_success, - expected_code, read_code) - - def test_expected_succes_list_match(self): - expected_code = [202, 204] - read_code = 202 - resp = self.rest_client.expected_success(expected_code, read_code) - # Assert None resp on success - self.assertFalse(resp) - - def test_expected_succes_list_no_match(self): - expected_code = [202, 204] - read_code = 200 - self.assertRaises(exceptions.InvalidHttpSuccessCode, - self.rest_client.expected_success, - expected_code, read_code) - - def test_non_success_expected_int(self): - expected_code = 404 - read_code = 202 - self.assertRaises(AssertionError, self.rest_client.expected_success, - expected_code, read_code) - - def test_non_success_expected_list(self): - expected_code = [404, 202] - read_code = 202 - self.assertRaises(AssertionError, self.rest_client.expected_success, - expected_code, read_code) - - -class TestResponseBody(base.TestCase): - - def test_str(self): - response = {'status': 200} - body = {'key1': 'value1'} - actual = rest_client.ResponseBody(response, body) - self.assertEqual("response: %s\nBody: %s" % (response, body), - str(actual)) - - -class TestResponseBodyData(base.TestCase): - - def test_str(self): - response = {'status': 200} - data = 'data1' - actual = rest_client.ResponseBodyData(response, data) - self.assertEqual("response: %s\nBody: %s" % (response, data), - str(actual)) - - -class TestResponseBodyList(base.TestCase): - - def test_str(self): - response = {'status': 200} - body = ['value1', 'value2', 'value3'] - actual = rest_client.ResponseBodyList(response, body) - self.assertEqual("response: %s\nBody: %s" % (response, body), - str(actual)) - - -class TestJSONSchemaValidationBase(base.TestCase): - - class Response(dict): - - def __getattr__(self, attr): - return self[attr] - - def __setattr__(self, attr, value): - self[attr] = value - - def setUp(self): - super(TestJSONSchemaValidationBase, self).setUp() - self.fake_auth_provider = fake_auth_provider.FakeAuthProvider() - self.rest_client = rest_client.RestClient( - self.fake_auth_provider, None, None) - - def _test_validate_pass(self, schema, resp_body, status=200): - resp = self.Response() - resp.status = status - self.rest_client.validate_response(schema, resp, resp_body) - - def _test_validate_fail(self, schema, resp_body, status=200, - error_msg="HTTP response body is invalid"): - resp = self.Response() - resp.status = status - ex = self.assertRaises(exceptions.InvalidHTTPResponseBody, - self.rest_client.validate_response, - schema, resp, resp_body) - self.assertIn(error_msg, ex._error_string) - - -class TestRestClientJSONSchemaValidation(TestJSONSchemaValidationBase): - - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'integer', - }, - }, - 'required': ['foo'] - } - } - - def test_validate_pass_with_http_success_code(self): - body = {'foo': 12} - self._test_validate_pass(self.schema, body, status=200) - - def test_validate_pass_with_http_redirect_code(self): - body = {'foo': 12} - schema = copy.deepcopy(self.schema) - schema['status_code'] = 300 - self._test_validate_pass(schema, body, status=300) - - def test_validate_not_http_success_code(self): - schema = { - 'status_code': [200] - } - body = {} - self._test_validate_pass(schema, body, status=400) - - def test_validate_multiple_allowed_type(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': ['integer', 'string'], - }, - }, - 'required': ['foo'] - } - } - body = {'foo': 12} - self._test_validate_pass(schema, body) - body = {'foo': '12'} - self._test_validate_pass(schema, body) - - def test_validate_enable_additional_property_pass(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': {'type': 'integer'} - }, - 'additionalProperties': True, - 'required': ['foo'] - } - } - body = {'foo': 12, 'foo2': 'foo2value'} - self._test_validate_pass(schema, body) - - def test_validate_disable_additional_property_pass(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': {'type': 'integer'} - }, - 'additionalProperties': False, - 'required': ['foo'] - } - } - body = {'foo': 12} - self._test_validate_pass(schema, body) - - def test_validate_disable_additional_property_fail(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': {'type': 'integer'} - }, - 'additionalProperties': False, - 'required': ['foo'] - } - } - body = {'foo': 12, 'foo2': 'foo2value'} - self._test_validate_fail(schema, body) - - def test_validate_wrong_status_code(self): - schema = { - 'status_code': [202] - } - body = {} - resp = self.Response() - resp.status = 200 - ex = self.assertRaises(exceptions.InvalidHttpSuccessCode, - self.rest_client.validate_response, - schema, resp, body) - self.assertIn("Unexpected http success status code", ex._error_string) - - def test_validate_wrong_attribute_type(self): - body = {'foo': 1.2} - self._test_validate_fail(self.schema, body) - - def test_validate_unexpected_response_body(self): - schema = { - 'status_code': [200], - } - body = {'foo': 12} - self._test_validate_fail( - schema, body, - error_msg="HTTP response body should not exist") - - def test_validate_missing_response_body(self): - body = {} - self._test_validate_fail(self.schema, body) - - def test_validate_missing_required_attribute(self): - body = {'notfoo': 12} - self._test_validate_fail(self.schema, body) - - def test_validate_response_body_not_list(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'list_items': { - 'type': 'array', - 'items': {'foo': {'type': 'integer'}} - } - }, - 'required': ['list_items'], - } - } - body = {'foo': 12} - self._test_validate_fail(schema, body) - - def test_validate_response_body_list_pass(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'list_items': { - 'type': 'array', - 'items': {'foo': {'type': 'integer'}} - } - }, - 'required': ['list_items'], - } - } - body = {'list_items': [{'foo': 12}, {'foo': 10}]} - self._test_validate_pass(schema, body) - - -class TestRestClientJSONHeaderSchemaValidation(TestJSONSchemaValidationBase): - - schema = { - 'status_code': [200], - 'response_header': { - 'type': 'object', - 'properties': { - 'foo': {'type': 'integer'} - }, - 'required': ['foo'] - } - } - - def test_validate_header_schema_pass(self): - resp_body = {} - resp = self.Response() - resp.status = 200 - resp.foo = 12 - self.rest_client.validate_response(self.schema, resp, resp_body) - - def test_validate_header_schema_fail(self): - resp_body = {} - resp = self.Response() - resp.status = 200 - resp.foo = 1.2 - ex = self.assertRaises(exceptions.InvalidHTTPResponseHeader, - self.rest_client.validate_response, - self.schema, resp, resp_body) - self.assertIn("HTTP response header is invalid", ex._error_string) - - -class TestRestClientJSONSchemaFormatValidation(TestJSONSchemaValidationBase): - - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'string', - 'format': 'email' - } - }, - 'required': ['foo'] - } - } - - def test_validate_format_pass(self): - body = {'foo': 'example@example.com'} - self._test_validate_pass(self.schema, body) - - def test_validate_format_fail(self): - body = {'foo': 'wrong_email'} - self._test_validate_fail(self.schema, body) - - def test_validate_formats_in_oneOf_pass(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'string', - 'oneOf': [ - {'format': 'ipv4'}, - {'format': 'ipv6'} - ] - } - }, - 'required': ['foo'] - } - } - body = {'foo': '10.0.0.0'} - self._test_validate_pass(schema, body) - body = {'foo': 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'} - self._test_validate_pass(schema, body) - - def test_validate_formats_in_oneOf_fail_both_match(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'string', - 'oneOf': [ - {'format': 'ipv4'}, - {'format': 'ipv4'} - ] - } - }, - 'required': ['foo'] - } - } - body = {'foo': '10.0.0.0'} - self._test_validate_fail(schema, body) - - def test_validate_formats_in_oneOf_fail_no_match(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'string', - 'oneOf': [ - {'format': 'ipv4'}, - {'format': 'ipv6'} - ] - } - }, - 'required': ['foo'] - } - } - body = {'foo': 'wrong_ip_format'} - self._test_validate_fail(schema, body) - - def test_validate_formats_in_anyOf_pass(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'string', - 'anyOf': [ - {'format': 'ipv4'}, - {'format': 'ipv6'} - ] - } - }, - 'required': ['foo'] - } - } - body = {'foo': '10.0.0.0'} - self._test_validate_pass(schema, body) - body = {'foo': 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329'} - self._test_validate_pass(schema, body) - - def test_validate_formats_in_anyOf_pass_both_match(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'string', - 'anyOf': [ - {'format': 'ipv4'}, - {'format': 'ipv4'} - ] - } - }, - 'required': ['foo'] - } - } - body = {'foo': '10.0.0.0'} - self._test_validate_pass(schema, body) - - def test_validate_formats_in_anyOf_fail_no_match(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'string', - 'anyOf': [ - {'format': 'ipv4'}, - {'format': 'ipv6'} - ] - } - }, - 'required': ['foo'] - } - } - body = {'foo': 'wrong_ip_format'} - self._test_validate_fail(schema, body) - - def test_validate_formats_pass_for_unknow_format(self): - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': { - 'type': 'string', - 'format': 'UNKNOWN' - } - }, - 'required': ['foo'] - } - } - body = {'foo': 'example@example.com'} - self._test_validate_pass(schema, body) - - -class TestRestClientJSONSchemaValidatorVersion(TestJSONSchemaValidationBase): - - schema = { - 'status_code': [200], - 'response_body': { - 'type': 'object', - 'properties': { - 'foo': {'type': 'string'} - } - } - } - - def test_current_json_schema_validator_version(self): - with mockpatch.PatchObject(jsonschema.Draft4Validator, - "check_schema") as chk_schema: - body = {'foo': 'test'} - self._test_validate_pass(self.schema, body) - chk_schema.mock.assert_called_once_with( - self.schema['response_body']) diff --git a/tempest_lib/tests/test_ssh.py b/tempest_lib/tests/test_ssh.py deleted file mode 100644 index 140bdf0..0000000 --- a/tempest_lib/tests/test_ssh.py +++ /dev/null @@ -1,253 +0,0 @@ -# Copyright 2014 OpenStack Foundation -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -from io import StringIO -import socket -import time - -import mock -import six -import testtools - -from tempest_lib.common import ssh -from tempest_lib import exceptions -from tempest_lib.tests import base - - -class TestSshClient(base.TestCase): - - SELECT_POLLIN = 1 - - @mock.patch('paramiko.RSAKey.from_private_key') - @mock.patch('six.StringIO') - def test_pkey_calls_paramiko_RSAKey(self, cs_mock, rsa_mock): - cs_mock.return_value = mock.sentinel.csio - pkey = 'mykey' - ssh.Client('localhost', 'root', pkey=pkey) - rsa_mock.assert_called_once_with(mock.sentinel.csio) - cs_mock.assert_called_once_with('mykey') - rsa_mock.reset_mock() - cs_mock.reset_mock() - pkey = mock.sentinel.pkey - # Shouldn't call out to load a file from RSAKey, since - # a sentinel isn't a basestring... - ssh.Client('localhost', 'root', pkey=pkey) - self.assertEqual(0, rsa_mock.call_count) - self.assertEqual(0, cs_mock.call_count) - - def _set_ssh_connection_mocks(self): - client_mock = mock.MagicMock() - client_mock.connect.return_value = True - return (self.patch('paramiko.SSHClient'), - self.patch('paramiko.AutoAddPolicy'), - client_mock) - - def test_get_ssh_connection(self): - c_mock, aa_mock, client_mock = self._set_ssh_connection_mocks() - s_mock = self.patch('time.sleep') - - c_mock.return_value = client_mock - aa_mock.return_value = mock.sentinel.aa - - # Test normal case for successful connection on first try - client = ssh.Client('localhost', 'root', timeout=2) - client._get_ssh_connection(sleep=1) - - aa_mock.assert_called_once_with() - client_mock.set_missing_host_key_policy.assert_called_once_with( - mock.sentinel.aa) - expected_connect = [mock.call( - 'localhost', - username='root', - pkey=None, - key_filename=None, - look_for_keys=False, - timeout=10.0, - password=None - )] - self.assertEqual(expected_connect, client_mock.connect.mock_calls) - self.assertEqual(0, s_mock.call_count) - - def test_get_ssh_connection_two_attemps(self): - c_mock, aa_mock, client_mock = self._set_ssh_connection_mocks() - - c_mock.return_value = client_mock - client_mock.connect.side_effect = [ - socket.error, - mock.MagicMock() - ] - - client = ssh.Client('localhost', 'root', timeout=1) - start_time = int(time.time()) - client._get_ssh_connection(sleep=1) - end_time = int(time.time()) - self.assertLess((end_time - start_time), 4) - self.assertGreater((end_time - start_time), 1) - - def test_get_ssh_connection_timeout(self): - c_mock, aa_mock, client_mock = self._set_ssh_connection_mocks() - - c_mock.return_value = client_mock - client_mock.connect.side_effect = [ - socket.error, - socket.error, - socket.error, - ] - - client = ssh.Client('localhost', 'root', timeout=2) - start_time = int(time.time()) - with testtools.ExpectedException(exceptions.SSHTimeout): - client._get_ssh_connection() - end_time = int(time.time()) - self.assertLess((end_time - start_time), 5) - self.assertGreaterEqual((end_time - start_time), 2) - - @mock.patch('select.POLLIN', SELECT_POLLIN, create=True) - def test_timeout_in_exec_command(self): - chan_mock, poll_mock, _ = self._set_mocks_for_select([0, 0, 0], True) - - # Test for a timeout condition immediately raised - client = ssh.Client('localhost', 'root', timeout=2) - with testtools.ExpectedException(exceptions.TimeoutException): - client.exec_command("test") - - chan_mock.fileno.assert_called_once_with() - chan_mock.exec_command.assert_called_once_with("test") - chan_mock.shutdown_write.assert_called_once_with() - - poll_mock.register.assert_called_once_with( - chan_mock, self.SELECT_POLLIN) - poll_mock.poll.assert_called_once_with(10) - - @mock.patch('select.POLLIN', SELECT_POLLIN, create=True) - def test_exec_command(self): - chan_mock, poll_mock, select_mock = ( - self._set_mocks_for_select([[1, 0, 0]], True)) - closed_prop = mock.PropertyMock(return_value=True) - type(chan_mock).closed = closed_prop - - chan_mock.recv_exit_status.return_value = 0 - chan_mock.recv.return_value = b'' - chan_mock.recv_stderr.return_value = b'' - - client = ssh.Client('localhost', 'root', timeout=2) - client.exec_command("test") - - chan_mock.fileno.assert_called_once_with() - chan_mock.exec_command.assert_called_once_with("test") - chan_mock.shutdown_write.assert_called_once_with() - - select_mock.assert_called_once_with() - poll_mock.register.assert_called_once_with( - chan_mock, self.SELECT_POLLIN) - poll_mock.poll.assert_called_once_with(10) - chan_mock.recv_ready.assert_called_once_with() - chan_mock.recv.assert_called_once_with(1024) - chan_mock.recv_stderr_ready.assert_called_once_with() - chan_mock.recv_stderr.assert_called_once_with(1024) - chan_mock.recv_exit_status.assert_called_once_with() - closed_prop.assert_called_once_with() - - def _set_mocks_for_select(self, poll_data, ito_value=False): - gsc_mock = self.patch('tempest_lib.common.ssh.Client.' - '_get_ssh_connection') - ito_mock = self.patch('tempest_lib.common.ssh.Client._is_timed_out') - csp_mock = self.patch( - 'tempest_lib.common.ssh.Client._can_system_poll') - csp_mock.return_value = True - - select_mock = self.patch('select.poll', create=True) - client_mock = mock.MagicMock() - tran_mock = mock.MagicMock() - chan_mock = mock.MagicMock() - poll_mock = mock.MagicMock() - - select_mock.return_value = poll_mock - gsc_mock.return_value = client_mock - ito_mock.return_value = ito_value - client_mock.get_transport.return_value = tran_mock - tran_mock.open_session.return_value = chan_mock - if isinstance(poll_data[0], list): - poll_mock.poll.side_effect = poll_data - else: - poll_mock.poll.return_value = poll_data - - return chan_mock, poll_mock, select_mock - - _utf8_string = six.unichr(1071) - _utf8_bytes = _utf8_string.encode("utf-8") - - @mock.patch('select.POLLIN', SELECT_POLLIN, create=True) - def test_exec_good_command_output(self): - chan_mock, poll_mock, _ = self._set_mocks_for_select([1, 0, 0]) - closed_prop = mock.PropertyMock(return_value=True) - type(chan_mock).closed = closed_prop - - chan_mock.recv_exit_status.return_value = 0 - chan_mock.recv.side_effect = [self._utf8_bytes[0:1], - self._utf8_bytes[1:], b'R', b''] - chan_mock.recv_stderr.return_value = b'' - - client = ssh.Client('localhost', 'root', timeout=2) - out_data = client.exec_command("test") - self.assertEqual(self._utf8_string + 'R', out_data) - - @mock.patch('select.POLLIN', SELECT_POLLIN, create=True) - def test_exec_bad_command_output(self): - chan_mock, poll_mock, _ = self._set_mocks_for_select([1, 0, 0]) - closed_prop = mock.PropertyMock(return_value=True) - type(chan_mock).closed = closed_prop - - chan_mock.recv_exit_status.return_value = 1 - chan_mock.recv.return_value = b'' - chan_mock.recv_stderr.side_effect = [b'R', self._utf8_bytes[0:1], - self._utf8_bytes[1:], b''] - - client = ssh.Client('localhost', 'root', timeout=2) - exc = self.assertRaises(exceptions.SSHExecCommandFailed, - client.exec_command, "test") - self.assertIn('R' + self._utf8_string, six.text_type(exc)) - - def test_exec_command_no_select(self): - gsc_mock = self.patch('tempest_lib.common.ssh.Client.' - '_get_ssh_connection') - csp_mock = self.patch( - 'tempest_lib.common.ssh.Client._can_system_poll') - csp_mock.return_value = False - - select_mock = self.patch('select.poll', create=True) - client_mock = mock.MagicMock() - tran_mock = mock.MagicMock() - chan_mock = mock.MagicMock() - - # Test for proper reading of STDOUT and STDERROR - - gsc_mock.return_value = client_mock - client_mock.get_transport.return_value = tran_mock - tran_mock.open_session.return_value = chan_mock - chan_mock.recv_exit_status.return_value = 0 - - std_out_mock = mock.MagicMock(StringIO) - std_err_mock = mock.MagicMock(StringIO) - chan_mock.makefile.return_value = std_out_mock - chan_mock.makefile_stderr.return_value = std_err_mock - - client = ssh.Client('localhost', 'root', timeout=2) - client.exec_command("test") - - chan_mock.makefile.assert_called_once_with('rb', 1024) - chan_mock.makefile_stderr.assert_called_once_with('rb', 1024) - std_out_mock.read.assert_called_once_with() - std_err_mock.read.assert_called_once_with() - self.assertFalse(select_mock.called) diff --git a/tempest_lib/tests/test_tempest_lib.py b/tempest_lib/tests/test_tempest_lib.py deleted file mode 100644 index 76d74a6..0000000 --- a/tempest_lib/tests/test_tempest_lib.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- - -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -test_tempest_lib ----------------------------------- - -Tests for `tempest_lib` module. -""" - -from tempest_lib.tests import base - - -class TestTempest_lib(base.TestCase): - - def test_something(self): - pass |