From a905e5fe0713a55c7b7ee7384b145fc3f4a18ba9 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Fri, 9 Dec 2011 14:26:06 -0500 Subject: [PATCH] Accept 1 and 2 as version choices - removes all unused imports - update .gitignore with new venv path Change-Id: I3e8199b72dc83268115133d7c73335ffb6060f9a --- .gitignore | 2 +- novaclient/keystone/client.py | 1 + novaclient/shell.py | 5 ++++- novaclient/v1_0/base.py | 1 - novaclient/v1_0/shell.py | 1 - novaclient/v1_1/keypairs.py | 1 - tests/fakes.py | 4 ---- tests/test_base.py | 4 +--- tests/test_shell.py | 5 ++--- tests/v1_0/fakes.py | 2 -- tests/v1_0/test_accounts.py | 4 ++-- tests/v1_0/test_auth.py | 2 +- tests/v1_0/test_backup_schedules.py | 2 +- tests/v1_0/test_flavors.py | 2 +- tests/v1_0/test_images.py | 2 +- tests/v1_0/test_ipgroups.py | 2 +- tests/v1_0/test_servers.py | 2 +- tests/v1_0/test_shell.py | 6 +++--- tests/v1_0/test_zones.py | 4 +--- tests/v1_0/utils.py | 1 - tests/v1_1/test_auth.py | 1 - tests/v1_1/test_flavors.py | 2 +- tests/v1_1/test_floating_ips.py | 3 +-- tests/v1_1/test_images.py | 2 +- tests/v1_1/test_keypairs.py | 2 +- tests/v1_1/test_limits.py | 2 +- tests/v1_1/test_quotas.py | 8 +++----- tests/v1_1/test_security_group_rules.py | 3 +-- tests/v1_1/test_security_groups.py | 3 +-- tests/v1_1/test_servers.py | 2 +- tests/v1_1/test_shell.py | 4 ++-- tests/v1_1/test_zones.py | 3 +-- 32 files changed, 35 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index 33dc94868..28d20be52 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .coverage -.novaclient-venv +.venv *,cover cover *.pyc diff --git a/novaclient/keystone/client.py b/novaclient/keystone/client.py index ec2ab6661..5cf87d357 100644 --- a/novaclient/keystone/client.py +++ b/novaclient/keystone/client.py @@ -14,6 +14,7 @@ # under the License. import copy + from novaclient.keystone import tenants from novaclient.keystone import users diff --git a/novaclient/shell.py b/novaclient/shell.py index 4d6952e30..cee4e1d78 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -22,7 +22,6 @@ Command-line interface to the OpenStack Nova API. import argparse import httplib2 import os -import prettytable import sys from novaclient import exceptions as exc @@ -105,8 +104,10 @@ class OpenStackComputeShell(object): try: actions_module = { + '1': shell_v1_0, '1.0': shell_v1_0, '1.1': shell_v1_1, + '2': shell_v1_1, }[version] except KeyError: actions_module = shell_v1_0 @@ -212,8 +213,10 @@ class OpenStackComputeShell(object): def get_api_class(self, version): try: return { + "1": shell_v1_0.CLIENT_CLASS, "1.0": shell_v1_0.CLIENT_CLASS, "1.1": shell_v1_1.CLIENT_CLASS, + "2": shell_v1_1.CLIENT_CLASS, }[version] except KeyError: return shell_v1_0.CLIENT_CLASS diff --git a/novaclient/v1_0/base.py b/novaclient/v1_0/base.py index 5c09e9d99..f03eb6153 100644 --- a/novaclient/v1_0/base.py +++ b/novaclient/v1_0/base.py @@ -20,7 +20,6 @@ Base utilities to build API operation managers and objects on top of. """ from novaclient import base -from novaclient import exceptions # Python 2.4 compat diff --git a/novaclient/v1_0/shell.py b/novaclient/v1_0/shell.py index b8a5867d7..0a0fbdf36 100644 --- a/novaclient/v1_0/shell.py +++ b/novaclient/v1_0/shell.py @@ -17,7 +17,6 @@ import getpass import os -import uuid from novaclient import exceptions from novaclient import utils diff --git a/novaclient/v1_1/keypairs.py b/novaclient/v1_1/keypairs.py index 3ee8d8b49..76b65a80c 100644 --- a/novaclient/v1_1/keypairs.py +++ b/novaclient/v1_1/keypairs.py @@ -16,7 +16,6 @@ """ Keypair interface (1.1 extension). """ -import os from novaclient import base diff --git a/tests/fakes.py b/tests/fakes.py index e1b07324d..248214ff0 100644 --- a/tests/fakes.py +++ b/tests/fakes.py @@ -6,8 +6,6 @@ wrong the tests might raise AssertionError. I've indicated in comments the places where actual behavior differs from the spec. """ -import novaclient.client - def assert_has_keys(dict, required=[], optional=[]): keys = dict.keys() @@ -15,7 +13,6 @@ def assert_has_keys(dict, required=[], optional=[]): try: assert k in keys except AssertionError: - allowed_keys = set(required) | set(optional) extra_keys = set(keys).difference(set(required + optional)) raise AssertionError("found unexpected keys: %s" % list(extra_keys)) @@ -50,7 +47,6 @@ class FakeClient(object): found = False for entry in self.client.callstack: - called = entry[0:2] if expected == entry[0:2]: found = True break diff --git a/tests/test_base.py b/tests/test_base.py index c5e3fc796..8109d914e 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -1,10 +1,8 @@ -import mock - from novaclient import base from novaclient import exceptions from novaclient.v1_0 import flavors -from tests.v1_0 import fakes from tests import utils +from tests.v1_0 import fakes cs = fakes.FakeClient() diff --git a/tests/test_shell.py b/tests/test_shell.py index 27d8fd367..74dfc1150 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -1,9 +1,8 @@ import os -import mock import httplib2 -from novaclient.shell import OpenStackComputeShell from novaclient import exceptions +import novaclient.shell from tests import utils @@ -23,7 +22,7 @@ class ShellTest(utils.TestCase): # Make a fake shell object, a helping wrapper to call it, and a quick # way of asserting that certain API calls were made. global shell, _shell, assert_called, assert_called_anytime - _shell = OpenStackComputeShell() + _shell = novaclient.shell.OpenStackComputeShell() shell = lambda cmd: _shell.main(cmd.split()) def tearDown(self): diff --git a/tests/v1_0/fakes.py b/tests/v1_0/fakes.py index a6271c658..e969188a2 100644 --- a/tests/v1_0/fakes.py +++ b/tests/v1_0/fakes.py @@ -1,6 +1,4 @@ import httplib2 -import urllib -import urlparse from novaclient import client as base_client from novaclient.v1_0 import client diff --git a/tests/v1_0/test_accounts.py b/tests/v1_0/test_accounts.py index 5c001ec24..79257fa35 100644 --- a/tests/v1_0/test_accounts.py +++ b/tests/v1_0/test_accounts.py @@ -1,7 +1,7 @@ import StringIO -from tests.v1_0 import fakes from tests import utils +from tests.v1_0 import fakes cs = fakes.FakeClient() @@ -10,7 +10,7 @@ cs = fakes.FakeClient() class AccountsTest(utils.TestCase): def test_instance_creation_for_account(self): - s = cs.accounts.create_instance_for( + cs.accounts.create_instance_for( account_id='test_account', name="My server", image=1, diff --git a/tests/v1_0/test_auth.py b/tests/v1_0/test_auth.py index 474bcbaff..aad912aaf 100644 --- a/tests/v1_0/test_auth.py +++ b/tests/v1_0/test_auth.py @@ -1,8 +1,8 @@ import httplib2 import mock -from novaclient.v1_0 import client from novaclient import exceptions +from novaclient.v1_0 import client from tests import utils diff --git a/tests/v1_0/test_backup_schedules.py b/tests/v1_0/test_backup_schedules.py index 5833aced3..c4b5c1086 100644 --- a/tests/v1_0/test_backup_schedules.py +++ b/tests/v1_0/test_backup_schedules.py @@ -1,6 +1,6 @@ from novaclient.v1_0 import backup_schedules -from tests.v1_0 import fakes from tests import utils +from tests.v1_0 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_0/test_flavors.py b/tests/v1_0/test_flavors.py index a10640018..1b0b24a33 100644 --- a/tests/v1_0/test_flavors.py +++ b/tests/v1_0/test_flavors.py @@ -1,7 +1,7 @@ from novaclient import exceptions from novaclient.v1_0 import flavors -from tests.v1_0 import fakes from tests import utils +from tests.v1_0 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_0/test_images.py b/tests/v1_0/test_images.py index ccbe476c7..138b31580 100644 --- a/tests/v1_0/test_images.py +++ b/tests/v1_0/test_images.py @@ -1,6 +1,6 @@ from novaclient.v1_0 import images -from tests.v1_0 import fakes from tests import utils +from tests.v1_0 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_0/test_ipgroups.py b/tests/v1_0/test_ipgroups.py index 29d37444a..68adae6bb 100644 --- a/tests/v1_0/test_ipgroups.py +++ b/tests/v1_0/test_ipgroups.py @@ -1,6 +1,6 @@ from novaclient.v1_0 import ipgroups -from tests.v1_0 import fakes from tests import utils +from tests.v1_0 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_0/test_servers.py b/tests/v1_0/test_servers.py index 4db6c20c1..8782bb4bb 100644 --- a/tests/v1_0/test_servers.py +++ b/tests/v1_0/test_servers.py @@ -1,8 +1,8 @@ import StringIO from novaclient.v1_0 import servers -from tests.v1_0 import fakes from tests import utils +from tests.v1_0 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_0/test_shell.py b/tests/v1_0/test_shell.py index 9dfbeef16..1700b51f3 100644 --- a/tests/v1_0/test_shell.py +++ b/tests/v1_0/test_shell.py @@ -1,10 +1,10 @@ import os import mock -from novaclient.shell import OpenStackComputeShell from novaclient import exceptions -from tests.v1_0 import fakes +import novaclient.shell from tests import utils +from tests.v1_0 import fakes class ShellTest(utils.TestCase): @@ -19,7 +19,7 @@ class ShellTest(utils.TestCase): 'NOVA_VERSION': '1.0', } - self.shell = OpenStackComputeShell() + self.shell = novaclient.shell.OpenStackComputeShell() self.shell.get_api_class = lambda *_: fakes.FakeClient def tearDown(self): diff --git a/tests/v1_0/test_zones.py b/tests/v1_0/test_zones.py index 10b1ceaf9..d389d1442 100644 --- a/tests/v1_0/test_zones.py +++ b/tests/v1_0/test_zones.py @@ -1,9 +1,7 @@ -import StringIO - from novaclient.v1_0 import zones -from tests.v1_0 import fakes from tests import utils +from tests.v1_0 import fakes os = fakes.FakeClient() diff --git a/tests/v1_0/utils.py b/tests/v1_0/utils.py index f878a5e26..308d6f21e 100644 --- a/tests/v1_0/utils.py +++ b/tests/v1_0/utils.py @@ -19,7 +19,6 @@ def assert_has_keys(dict, required=[], optional=[]): keys = dict.keys() for k in required: assert_in(k, keys, "required key %s missing from %s" % (k, dict)) - allowed_keys = set(required) | set(optional) extra_keys = set(keys).difference(set(required + optional)) if extra_keys: fail("found unexpected keys: %s" % list(extra_keys)) diff --git a/tests/v1_1/test_auth.py b/tests/v1_1/test_auth.py index 2a2c2bd26..d73e71404 100644 --- a/tests/v1_1/test_auth.py +++ b/tests/v1_1/test_auth.py @@ -3,7 +3,6 @@ import json import mock import urlparse - from novaclient.v1_1 import client from novaclient import exceptions from tests import utils diff --git a/tests/v1_1/test_flavors.py b/tests/v1_1/test_flavors.py index c48c8d18b..7ab9eda98 100644 --- a/tests/v1_1/test_flavors.py +++ b/tests/v1_1/test_flavors.py @@ -1,7 +1,7 @@ from novaclient import exceptions from novaclient.v1_1 import flavors -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_1/test_floating_ips.py b/tests/v1_1/test_floating_ips.py index bbb68ea01..c1ffb2487 100644 --- a/tests/v1_1/test_floating_ips.py +++ b/tests/v1_1/test_floating_ips.py @@ -1,7 +1,6 @@ -from novaclient import exceptions from novaclient.v1_1 import floating_ips -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_1/test_images.py b/tests/v1_1/test_images.py index 07609af75..71676e165 100644 --- a/tests/v1_1/test_images.py +++ b/tests/v1_1/test_images.py @@ -1,6 +1,6 @@ from novaclient.v1_1 import images -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_1/test_keypairs.py b/tests/v1_1/test_keypairs.py index 19351616b..10afd2497 100644 --- a/tests/v1_1/test_keypairs.py +++ b/tests/v1_1/test_keypairs.py @@ -1,6 +1,6 @@ from novaclient.v1_1 import keypairs -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_1/test_limits.py b/tests/v1_1/test_limits.py index 649e2414c..f41a2e76b 100644 --- a/tests/v1_1/test_limits.py +++ b/tests/v1_1/test_limits.py @@ -1,7 +1,7 @@ from novaclient.v1_1 import limits -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_1/test_quotas.py b/tests/v1_1/test_quotas.py index 254850240..7e8bb6fe9 100644 --- a/tests/v1_1/test_quotas.py +++ b/tests/v1_1/test_quotas.py @@ -13,10 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from novaclient import exceptions -from novaclient.v1_1 import quotas -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() @@ -26,12 +24,12 @@ class QuotaSetsTest(utils.TestCase): def test_tenant_quotas_get(self): tenant_id = 'test' - qs = cs.quotas.get(tenant_id) + cs.quotas.get(tenant_id) cs.assert_called('GET', '/os-quota-sets/%s' % tenant_id) def test_tenant_quotas_defaults(self): tenant_id = 'test' - q = cs.quotas.defaults(tenant_id) + cs.quotas.defaults(tenant_id) cs.assert_called('GET', '/os-quota-sets/%s/defaults' % tenant_id) def test_update_quota(self): diff --git a/tests/v1_1/test_security_group_rules.py b/tests/v1_1/test_security_group_rules.py index b9e9527b6..872dab78d 100644 --- a/tests/v1_1/test_security_group_rules.py +++ b/tests/v1_1/test_security_group_rules.py @@ -1,7 +1,6 @@ -from novaclient import exceptions from novaclient.v1_1 import security_group_rules -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_1/test_security_groups.py b/tests/v1_1/test_security_groups.py index 48982cb14..fe92ae31b 100644 --- a/tests/v1_1/test_security_groups.py +++ b/tests/v1_1/test_security_groups.py @@ -1,7 +1,6 @@ -from novaclient import exceptions from novaclient.v1_1 import security_groups -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_1/test_servers.py b/tests/v1_1/test_servers.py index cac5816a0..8a716c501 100644 --- a/tests/v1_1/test_servers.py +++ b/tests/v1_1/test_servers.py @@ -1,8 +1,8 @@ import StringIO from novaclient.v1_1 import servers -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes cs = fakes.FakeClient() diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py index 0f02967d5..4c5c30246 100644 --- a/tests/v1_1/test_shell.py +++ b/tests/v1_1/test_shell.py @@ -3,7 +3,7 @@ import mock import sys import tempfile -from novaclient.shell import OpenStackComputeShell +import novaclient.shell from novaclient import exceptions from tests.v1_1 import fakes from tests import utils @@ -23,7 +23,7 @@ class ShellTest(utils.TestCase): 'NOVA_URL': 'http://no.where', } - self.shell = OpenStackComputeShell() + self.shell = novaclient.shell.OpenStackComputeShell() self.shell.get_api_class = lambda *_: fakes.FakeClient def tearDown(self): diff --git a/tests/v1_1/test_zones.py b/tests/v1_1/test_zones.py index 9d36027c8..9bc68059c 100644 --- a/tests/v1_1/test_zones.py +++ b/tests/v1_1/test_zones.py @@ -1,8 +1,7 @@ -import StringIO from novaclient.v1_1 import zones -from tests.v1_1 import fakes from tests import utils +from tests.v1_1 import fakes os = fakes.FakeClient()