diff --git a/Authors b/Authors index 0d95d5961..363eb3236 100644 --- a/Authors +++ b/Authors @@ -5,6 +5,7 @@ Adrian Smith Ahmad Hassan Alex Meade Alexander Sakhnov +Alexander Kovalev Alvaro Lopez Garcia Andrew Bogott Andrew Clay Shafer @@ -49,6 +50,7 @@ Derek Higgins Devdeep Singh Devendra Modium Devin Carlen +Dina Belova Donal Lafferty Dong-In David Kang Doug Hellmann diff --git a/nova/notifier/list_notifier.py b/nova/notifier/list_notifier.py index 2f5c9e4a8..445276229 100644 --- a/nova/notifier/list_notifier.py +++ b/nova/notifier/list_notifier.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import nova.exception +from nova import exception from nova import flags from nova import log as logging from nova.openstack.common import cfg @@ -50,7 +50,7 @@ def _get_drivers(): for notification_driver in FLAGS.list_notifier_drivers: try: drivers.append(utils.import_object(notification_driver)) - except nova.exception.ClassNotFound as e: + except exception.ClassNotFound as e: drivers.append(ImportFailureNotifier(e)) return drivers diff --git a/nova/notifier/rabbit_notifier.py b/nova/notifier/rabbit_notifier.py index 639fe6784..e57ea9702 100644 --- a/nova/notifier/rabbit_notifier.py +++ b/nova/notifier/rabbit_notifier.py @@ -17,9 +17,11 @@ import nova.context from nova import flags +from nova import log as logging from nova.openstack.common import cfg from nova import rpc +LOG = logging.getLogger(__name__) notification_topic_opt = cfg.ListOpt('notification_topics', default=['notifications', ], diff --git a/nova/rpc/__init__.py b/nova/rpc/__init__.py index 412a32b7d..4acc5634c 100644 --- a/nova/rpc/__init__.py +++ b/nova/rpc/__init__.py @@ -19,8 +19,7 @@ from nova import flags from nova.openstack.common import cfg -from nova.rpc.common import RemoteError, LOG -from nova.utils import import_object +from nova import utils rpc_backend_opt = cfg.StrOpt('rpc_backend', @@ -199,5 +198,5 @@ def _get_impl(): """Delay import of rpc_backend until FLAGS are loaded.""" global _RPCIMPL if _RPCIMPL is None: - _RPCIMPL = import_object(FLAGS.rpc_backend) + _RPCIMPL = utils.import_object(FLAGS.rpc_backend) return _RPCIMPL diff --git a/nova/rpc/amqp.py b/nova/rpc/amqp.py index 2d549e162..367eaf1e8 100644 --- a/nova/rpc/amqp.py +++ b/nova/rpc/amqp.py @@ -37,8 +37,10 @@ from nova import context from nova import exception from nova import flags from nova import local +from nova import log as logging import nova.rpc.common as rpc_common -from nova.rpc.common import LOG + +LOG = logging.getLogger(__name__) FLAGS = flags.FLAGS diff --git a/nova/rpc/impl_carrot.py b/nova/rpc/impl_carrot.py index 806b4451d..ea10cb346 100644 --- a/nova/rpc/impl_carrot.py +++ b/nova/rpc/impl_carrot.py @@ -43,11 +43,12 @@ from nova import context from nova import exception from nova import flags from nova import local +from nova import log as logging from nova.rpc import common as rpc_common -from nova.rpc.common import RemoteError, LOG from nova.testing import fake FLAGS = flags.FLAGS +LOG = logging.getLogger(__name__) class Connection(carrot_connection.BrokerConnection, rpc_common.Connection): @@ -558,7 +559,7 @@ class MulticallWaiter(object): """Acks message and sets result.""" message.ack() if data['failure']: - self._results.put(RemoteError(*data['failure'])) + self._results.put(rpc_common.RemoteError(*data['failure'])) elif data.get('ending', False): self._got_ending = True else: diff --git a/nova/rpc/impl_qpid.py b/nova/rpc/impl_qpid.py index c229f3d8e..88e820e82 100644 --- a/nova/rpc/impl_qpid.py +++ b/nova/rpc/impl_qpid.py @@ -26,11 +26,12 @@ import qpid.messaging import qpid.messaging.exceptions from nova import flags +from nova import log as logging from nova.openstack.common import cfg from nova.rpc import amqp as rpc_amqp from nova.rpc import common as rpc_common -from nova.rpc.common import LOG +LOG = logging.getLogger(__name__) qpid_opts = [ cfg.StrOpt('qpid_hostname', diff --git a/nova/scheduler/driver.py b/nova/scheduler/driver.py index 292161867..5981252ce 100644 --- a/nova/scheduler/driver.py +++ b/nova/scheduler/driver.py @@ -31,6 +31,7 @@ from nova import flags from nova import log as logging from nova.openstack.common import cfg from nova import rpc +from nova.rpc import common as rpc_common from nova import utils @@ -366,7 +367,7 @@ class Scheduler(object): {"method": 'compare_cpu', "args": {'cpu_info': oservice_ref['cpu_info']}}) - except rpc.RemoteError: + except rpc_common.RemoteError: src = instance_ref['host'] LOG.exception(_("host %(dest)s is not compatible with " "original host %(src)s.") % locals()) @@ -457,7 +458,7 @@ class Scheduler(object): {"method": 'get_instance_disk_info', "args": {'instance_name': instance_ref['name']}}) disk_infos = utils.loads(ret) - except rpc.RemoteError: + except rpc_common.RemoteError: LOG.exception(_("host %(dest)s is not compatible with " "original host %(src)s.") % locals()) raise diff --git a/nova/scheduler/vsa.py b/nova/scheduler/vsa.py index f47c19c96..275bc7581 100644 --- a/nova/scheduler/vsa.py +++ b/nova/scheduler/vsa.py @@ -29,8 +29,8 @@ from nova import rpc from nova import utils from nova.scheduler import driver from nova.scheduler import simple -from nova.vsa.api import VsaState from nova.volume import volume_types +from nova.vsa import api as vsa_api LOG = logging.getLogger(__name__) @@ -297,7 +297,8 @@ class VsaScheduler(simple.SimpleScheduler): except Exception: LOG.exception(_("Error creating volumes")) if vsa_id: - db.vsa_update(context, vsa_id, dict(status=VsaState.FAILED)) + db.vsa_update(context, vsa_id, + dict(status=vsa_api.VsaState.FAILED)) for vol in volume_params: if 'capabilities' in vol: @@ -351,7 +352,7 @@ class VsaScheduler(simple.SimpleScheduler): LOG.exception(_("Error creating volume")) if volume_ref['to_vsa_id']: db.vsa_update(context, volume_ref['to_vsa_id'], - dict(status=VsaState.FAILED)) + dict(status=vsa_api.VsaState.FAILED)) raise if host: diff --git a/nova/testing/runner.py b/nova/testing/runner.py index 70d7d7155..7ddf959db 100644 --- a/nova/testing/runner.py +++ b/nova/testing/runner.py @@ -132,13 +132,11 @@ class _Win32Colorizer(object): See _AnsiColorizer docstring. """ def __init__(self, stream): - from win32console import (GetStdHandle, STD_OUT_HANDLE, - FOREGROUND_RED, FOREGROUND_BLUE, - FOREGROUND_GREEN, FOREGROUND_INTENSITY) - red, green, blue, bold = (FOREGROUND_RED, FOREGROUND_GREEN, - FOREGROUND_BLUE, FOREGROUND_INTENSITY) + import win32console as win + red, green, blue, bold = (win.FOREGROUND_RED, win.FOREGROUND_GREEN, + win.FOREGROUND_BLUE, win.FOREGROUND_INTENSITY) self.stream = stream - self.screenBuffer = GetStdHandle(STD_OUT_HANDLE) + self.screenBuffer = win.GetStdHandle(win.STD_OUT_HANDLE) self._colors = { 'normal': red | green | blue, 'red': red | bold, diff --git a/nova/tests/fakelibvirt.py b/nova/tests/fakelibvirt.py index 2628de0fe..b8f9bb433 100644 --- a/nova/tests/fakelibvirt.py +++ b/nova/tests/fakelibvirt.py @@ -14,11 +14,12 @@ # License for the specific language governing permissions and limitations # under the License. -from xml.etree.ElementTree import fromstring as xml_to_tree +from xml.etree import ElementTree try: - from xml.etree.ElementTree import ParseError -except ImportError: - from xml.parsers.expat import ExpatError as ParseError + ParseError = ElementTree.ParseError +except AttributeError: + from xml.parsers import expat + ParseError = expat.ExpatError import uuid @@ -140,7 +141,7 @@ class NWFilter(object): self._parse_xml(xml) def _parse_xml(self, xml): - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) root = tree.find('.') self._name = root.get('name') @@ -162,7 +163,7 @@ class Domain(object): def _parse_definition(self, xml): try: - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) except ParseError: raise libvirtError(VIR_ERR_XML_DETAIL, VIR_FROM_DOMAIN, "Invalid XML.") @@ -300,13 +301,13 @@ class Domain(object): 123456789L] def attachDevice(self, xml): - disk_info = _parse_disk_info(xml_to_tree(xml)) + disk_info = _parse_disk_info(ElementTree.fromstring(xml)) disk_info['_attached'] = True self._def['devices']['disks'] += [disk_info] return True def detachDevice(self, xml): - disk_info = _parse_disk_info(xml_to_tree(xml)) + disk_info = _parse_disk_info(ElementTree.fromstring(xml)) disk_info['_attached'] = True return disk_info in self._def['devices']['disks'] @@ -398,7 +399,7 @@ class Domain(object): self._state = VIR_DOMAIN_RUNNING def snapshotCreateXML(self, xml, flags): - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) name = tree.find('./name').text snapshot = DomainSnapshot(name, self) self._snapshots[name] = snapshot @@ -735,7 +736,7 @@ class Connection(object): ''' def compareCPU(self, xml, flags): - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) arch_node = tree.find('./arch') if arch_node is not None: diff --git a/nova/tests/notifier/test_list_notifier.py b/nova/tests/notifier/test_list_notifier.py index 6579694e7..e5ba48b6f 100644 --- a/nova/tests/notifier/test_list_notifier.py +++ b/nova/tests/notifier/test_list_notifier.py @@ -16,7 +16,6 @@ import nova from nova import log as logging import nova.notifier.api -from nova.notifier.api import notify import nova.notifier.log_notifier import nova.notifier.no_op_notifier from nova.notifier import list_notifier @@ -59,7 +58,7 @@ class NotifierListTestCase(test.TestCase): self.flags(notification_driver='nova.notifier.list_notifier', list_notifier_drivers=['nova.notifier.no_op_notifier', 'nova.notifier.no_op_notifier']) - notify('publisher_id', 'event_type', + nova.notifier.api.notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 2) self.assertEqual(self.exception_count, 0) @@ -69,7 +68,8 @@ class NotifierListTestCase(test.TestCase): self.flags(notification_driver='nova.notifier.list_notifier', list_notifier_drivers=['nova.notifier.no_op_notifier', 'nova.notifier.log_notifier']) - notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3)) + nova.notifier.api.notify('publisher_id', + 'event_type', nova.notifier.api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 1) self.assertEqual(self.exception_count, 1) @@ -78,6 +78,7 @@ class NotifierListTestCase(test.TestCase): list_notifier_drivers=['nova.notifier.no_op_notifier', 'nova.notifier.logo_notifier', 'fdsjgsdfhjkhgsfkj']) - notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3)) + nova.notifier.api.notify('publisher_id', + 'event_type', nova.notifier.api.WARN, dict(a=3)) self.assertEqual(self.exception_count, 2) self.assertEqual(self.notify_count, 1) diff --git a/nova/tests/rpc/common.py b/nova/tests/rpc/common.py index f9727082d..320df834d 100644 --- a/nova/tests/rpc/common.py +++ b/nova/tests/rpc/common.py @@ -25,7 +25,7 @@ import nose from nova import context from nova import log as logging -from nova.rpc.common import RemoteError, Timeout +from nova.rpc import common as rpc_common from nova import test @@ -107,7 +107,7 @@ class _BaseRpcTestCase(test.TestCase): """ value = 42 - self.assertRaises(RemoteError, + self.assertRaises(rpc_common.RemoteError, self.rpc.call, self.context, 'test', @@ -119,7 +119,7 @@ class _BaseRpcTestCase(test.TestCase): {"method": "fail", "args": {"value": value}}) self.fail("should have thrown RemoteError") - except RemoteError as exc: + except rpc_common.RemoteError as exc: self.assertEqual(int(exc.value), value) def test_nested_calls(self): @@ -157,7 +157,7 @@ class _BaseRpcTestCase(test.TestCase): raise nose.SkipTest(_("RPC backend does not support timeouts")) value = 42 - self.assertRaises(Timeout, + self.assertRaises(rpc_common.Timeout, self.rpc.call, self.context, 'test', @@ -170,7 +170,7 @@ class _BaseRpcTestCase(test.TestCase): "args": {"value": value}}, timeout=1) self.fail("should have thrown Timeout") - except Timeout as exc: + except rpc_common.Timeout as exc: pass diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index ccf9d38d9..b92df7872 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -996,7 +996,7 @@ class SchedulerTestCase(test.TestCase): rpc.call(self.context, 'dest_queue', {'method': 'compare_cpu', 'args': {'cpu_info': 'fake_cpu_info'}}).AndRaise( - rpc.RemoteError()) + rpc_common.RemoteError()) self.mox.ReplayAll() self.assertRaises(rpc_common.RemoteError, diff --git a/nova/tests/test_SolidFireSanISCSIDriver.py b/nova/tests/test_SolidFireSanISCSIDriver.py index a856172b2..e2b5732ab 100644 --- a/nova/tests/test_SolidFireSanISCSIDriver.py +++ b/nova/tests/test_SolidFireSanISCSIDriver.py @@ -17,7 +17,7 @@ from nova import exception from nova import log as logging -from nova.volume.san import SolidFireSanISCSIDriver as SFID +from nova.volume import san from nova import test LOG = logging.getLogger(__name__) @@ -90,19 +90,21 @@ class SolidFireVolumeTestCase(test.TestCase): 'id': 1} def test_create_volume(self): - SFID._issue_api_request = self.fake_issue_api_request + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request) testvol = {'project_id': 'testprjid', 'name': 'testvol', 'size': 1} - sfv = SFID() + sfv = san.SolidFireSanISCSIDriver() model_update = sfv.create_volume(testvol) def test_create_volume_fails(self): - SFID._issue_api_request = self.fake_issue_api_request_fails + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request_fails) testvol = {'project_id': 'testprjid', 'name': 'testvol', 'size': 1} - sfv = SFID() + sfv = san.SolidFireSanISCSIDriver() try: sfv.create_volume(testvol) self.fail("Should have thrown Error") @@ -110,43 +112,49 @@ class SolidFireVolumeTestCase(test.TestCase): pass def test_create_sfaccount(self): - sfv = SFID() - SFID._issue_api_request = self.fake_issue_api_request + sfv = san.SolidFireSanISCSIDriver() + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request) account = sfv._create_sfaccount('project-id') self.assertNotEqual(account, None) def test_create_sfaccount_fails(self): - sfv = SFID() - SFID._issue_api_request = self.fake_issue_api_request_fails + sfv = san.SolidFireSanISCSIDriver() + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request_fails) account = sfv._create_sfaccount('project-id') self.assertEqual(account, None) def test_get_sfaccount_by_name(self): - sfv = SFID() - SFID._issue_api_request = self.fake_issue_api_request + sfv = san.SolidFireSanISCSIDriver() + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request) account = sfv._get_sfaccount_by_name('some-name') self.assertNotEqual(account, None) def test_get_sfaccount_by_name_fails(self): - sfv = SFID() - SFID._issue_api_request = self.fake_issue_api_request_fails + sfv = san.SolidFireSanISCSIDriver() + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request_fails) account = sfv._get_sfaccount_by_name('some-name') self.assertEqual(account, None) def test_delete_volume(self): - SFID._issue_api_request = self.fake_issue_api_request + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request) testvol = {'project_id': 'testprjid', 'name': 'test_volume', 'size': 1} - sfv = SFID() + sfv = san.SolidFireSanISCSIDriver() model_update = sfv.delete_volume(testvol) def test_delete_volume_fails_no_volume(self): - SFID._issue_api_request = self.fake_issue_api_request + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request) testvol = {'project_id': 'testprjid', 'name': 'no-name', 'size': 1} - sfv = SFID() + sfv = san.SolidFireSanISCSIDriver() try: model_update = sfv.delete_volume(testvol) self.fail("Should have thrown Error") @@ -154,22 +162,25 @@ class SolidFireVolumeTestCase(test.TestCase): pass def test_delete_volume_fails_account_lookup(self): - SFID._issue_api_request = self.fake_issue_api_request + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request) testvol = {'project_id': 'testprjid', 'name': 'no-name', 'size': 1} - sfv = SFID() + sfv = san.SolidFireSanISCSIDriver() self.assertRaises(exception.DuplicateSfVolumeNames, sfv.delete_volume, testvol) def test_get_cluster_info(self): - SFID._issue_api_request = self.fake_issue_api_request - sfv = SFID() + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request) + sfv = san.SolidFireSanISCSIDriver() sfv._get_cluster_info() def test_get_cluster_info_fail(self): - SFID._issue_api_request = self.fake_issue_api_request_fails - sfv = SFID() + self.stubs.Set(san.SolidFireSanISCSIDriver, '_issue_api_request', + self.fake_issue_api_request_fails) + sfv = san.SolidFireSanISCSIDriver() self.assertRaises(exception.SolidFireAPIException, sfv._get_cluster_info) diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py index 7591df0c9..2b46be867 100644 --- a/nova/tests/test_api.py +++ b/nova/tests/test_api.py @@ -18,13 +18,14 @@ """Unit tests for the API endpoint""" -import boto -from boto.ec2 import regioninfo -from boto.exception import EC2ResponseError import datetime import httplib import random import StringIO + +import boto +from boto.ec2 import regioninfo +from boto import exception as boto_exc import webob from nova import block_device @@ -271,8 +272,8 @@ class ApiEc2TestCase(test.TestCase): """Attempt to terminate an invalid instance""" self.expect_http() self.mox.ReplayAll() - self.assertRaises(EC2ResponseError, self.ec2.terminate_instances, - "i-00000005") + self.assertRaises(boto_exc.EC2ResponseError, + self.ec2.terminate_instances, "i-00000005") def test_get_all_key_pairs(self): """Test that, after creating a user and project and generating @@ -300,7 +301,7 @@ class ApiEc2TestCase(test.TestCase): try: self.ec2.create_key_pair('test') - except EC2ResponseError, e: + except boto_exc.EC2ResponseError, e: if e.code == 'KeyPairExists': pass else: @@ -352,8 +353,10 @@ class ApiEc2TestCase(test.TestCase): # dashes, and underscores. security_group_name = "aa #^% -=99" - self.assertRaises(EC2ResponseError, self.ec2.create_security_group, - security_group_name, 'test group') + self.assertRaises(boto_exc.EC2ResponseError, + self.ec2.create_security_group, + security_group_name, + 'test group') def test_group_name_valid_length_security_group(self): """Test that we sanely handle invalid security group names. @@ -365,8 +368,10 @@ class ApiEc2TestCase(test.TestCase): security_group_name = "".join(random.choice("poiuytrewqasdfghjklmnbvc") for x in range(random.randint(256, 266))) - self.assertRaises(EC2ResponseError, self.ec2.create_security_group, - security_group_name, 'test group') + self.assertRaises(boto_exc.EC2ResponseError, + self.ec2.create_security_group, + security_group_name, + 'test group') def test_authorize_revoke_security_group_cidr(self): """ @@ -393,7 +398,7 @@ class ApiEc2TestCase(test.TestCase): def _assert(message, *args): try: group.authorize(*args) - except EC2ResponseError as e: + except boto_exc.EC2ResponseError as e: self.assertEqual(e.status, 400, 'Expected status to be 400') self.assertIn(message, e.error_message, e.error_message) else: @@ -569,7 +574,7 @@ class ApiEc2TestCase(test.TestCase): # Can not delete the group while it is still used by # another group. - self.assertRaises(EC2ResponseError, + self.assertRaises(boto_exc.EC2ResponseError, self.ec2.delete_security_group, other_security_group_name) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index fa6510620..402ca0c6a 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -29,7 +29,7 @@ import webob.exc import nova import nova.common.policy from nova import compute -import nova.compute.api +from nova.compute import api as compute_api from nova.compute import aggregate_states from nova.compute import instance_types from nova.compute import manager as compute_manager @@ -1419,7 +1419,7 @@ class ComputeTestCase(BaseTestCase): # start test self.mox.ReplayAll() - self.assertRaises(rpc.RemoteError, + self.assertRaises(rpc_common.RemoteError, self.compute.live_migration, c, instance_id, inst_ref['host'], True) @@ -3316,7 +3316,7 @@ class ComputeAPIAggrTestCase(test.TestCase): def setUp(self): super(ComputeAPIAggrTestCase, self).setUp() - self.api = compute.AggregateAPI() + self.api = compute_api.AggregateAPI() self.context = context.get_admin_context() self.stubs.Set(rpc, 'call', fake_rpc_method) self.stubs.Set(rpc, 'cast', fake_rpc_method) diff --git a/nova/tests/test_fakelibvirt.py b/nova/tests/test_fakelibvirt.py index 31f98e151..ac3ceea2d 100644 --- a/nova/tests/test_fakelibvirt.py +++ b/nova/tests/test_fakelibvirt.py @@ -16,7 +16,7 @@ from nova import test -from xml.etree.ElementTree import fromstring as xml_to_tree +from xml.etree import ElementTree import fakelibvirt as libvirt @@ -252,7 +252,7 @@ class FakeLibvirtTests(test.TestCase): conn.defineXML(get_vm_xml()) dom = conn.lookupByName('testname') xml = dom.XMLDesc(0) - xml_to_tree(xml) + ElementTree.fromstring(xml) def _test_accepts_source_type(self, source_type): conn = self.get_openAuth_curry_func()('qemu:///system') @@ -260,7 +260,7 @@ class FakeLibvirtTests(test.TestCase): conn.defineXML(get_vm_xml(source_type=source_type)) dom = conn.lookupByName('testname') xml = dom.XMLDesc(0) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) elem = tree.find('./devices/disk/source') self.assertEquals(elem.get('file'), '/somefile') @@ -282,7 +282,7 @@ class FakeLibvirtTests(test.TestCase): conn.defineXML(get_vm_xml(interface_type=network_type)) dom = conn.lookupByName('testname') xml = dom.XMLDesc(0) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) elem = tree.find('./devices/interface') self.assertEquals(elem.get('type'), network_type) elem = elem.find('./source') @@ -298,7 +298,7 @@ class FakeLibvirtTests(test.TestCase): def test_getCapabilities(self): conn = self.get_openAuth_curry_func()('qemu:///system') - xml_to_tree(conn.getCapabilities()) + ElementTree.fromstring(conn.getCapabilities()) def test_nwfilter_define_undefine(self): conn = self.get_openAuth_curry_func()('qemu:///system') diff --git a/nova/tests/test_instance_types.py b/nova/tests/test_instance_types.py index 25244ece1..9057f1896 100644 --- a/nova/tests/test_instance_types.py +++ b/nova/tests/test_instance_types.py @@ -24,8 +24,8 @@ from nova import flags from nova import log as logging from nova import test from nova.compute import instance_types -from nova.db.sqlalchemy.session import get_session from nova.db.sqlalchemy import models +from nova.db.sqlalchemy import session as sql_session FLAGS = flags.FLAGS LOG = logging.getLogger(__name__) @@ -90,7 +90,7 @@ class InstanceTypeTestCase(test.TestCase): def test_get_all_instance_types(self): """Ensures that all instance types can be retrieved""" - session = get_session() + session = sql_session.get_session() total_instance_types = session.query(models.InstanceTypes).count() inst_types = instance_types.get_all_types() self.assertEqual(total_instance_types, len(inst_types)) diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 9b4225663..d8a44eec9 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -23,8 +23,8 @@ import shutil import sys import tempfile -from xml.etree.ElementTree import fromstring as xml_to_tree -from xml.dom.minidom import parseString as xml_to_dom +from xml.etree import ElementTree +from xml.dom import minidom from nova import context from nova import db @@ -149,7 +149,7 @@ class LibvirtVolumeTestCase(test.TestCase): connection_info = vol_driver.initialize_connection(vol, self.connr) mount_device = "vde" xml = libvirt_driver.connect_volume(connection_info, mount_device) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) dev_str = '/dev/disk/by-path/ip-%s-iscsi-%s-lun-0' % (location, iqn) self.assertEqual(tree.get('type'), 'block') self.assertEqual(tree.find('./source').get('dev'), dev_str) @@ -188,7 +188,7 @@ class LibvirtVolumeTestCase(test.TestCase): connection_info = vol_driver.initialize_connection(vol, self.connr) mount_device = "vde" xml = libvirt_driver.connect_volume(connection_info, mount_device) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) dev_str = '/dev/disk/by-path/ip-%s-iscsi-%s-lun-0' % (location, iqn) self.assertEqual(tree.get('type'), 'block') self.assertEqual(tree.find('./source').get('dev'), dev_str) @@ -211,7 +211,7 @@ class LibvirtVolumeTestCase(test.TestCase): connection_info = vol_driver.initialize_connection(vol, self.connr) mount_device = "vde" xml = libvirt_driver.connect_volume(connection_info, mount_device) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) self.assertEqual(tree.get('type'), 'network') self.assertEqual(tree.find('./source').get('protocol'), 'sheepdog') self.assertEqual(tree.find('./source').get('name'), name) @@ -226,7 +226,7 @@ class LibvirtVolumeTestCase(test.TestCase): connection_info = vol_driver.initialize_connection(vol, self.connr) mount_device = "vde" xml = libvirt_driver.connect_volume(connection_info, mount_device) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) self.assertEqual(tree.get('type'), 'network') self.assertEqual(tree.find('./source').get('protocol'), 'rbd') rbd_name = '%s/%s' % (FLAGS.rbd_pool, name) @@ -248,7 +248,7 @@ class LibvirtVolumeTestCase(test.TestCase): connection_info = vol_driver.initialize_connection(vol, self.connr) mount_device = "vde" xml = libvirt_driver.connect_volume(connection_info, mount_device) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) dev_str = '/dev/disk/by-path/ip-%s-iscsi-%s-lun-0' % (location, iqn) self.assertEqual(tree.get('type'), 'block') self.assertEqual(tree.find('./source').get('dev'), dev_str) @@ -716,7 +716,7 @@ class LibvirtConnTestCase(test.TestCase): conn = connection.LibvirtConnection(True) instance_ref = db.instance_create(self.context, instance_data) xml = conn.to_xml(instance_ref, network_info, None, False) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) interfaces = tree.findall("./devices/interface") self.assertEquals(len(interfaces), 2) parameters = interfaces[0].findall('./filterref/parameter') @@ -738,7 +738,7 @@ class LibvirtConnTestCase(test.TestCase): network_info = _fake_network_info(self.stubs, 1) xml = conn.to_xml(instance_ref, network_info) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) check = [ (lambda t: t.find('.').get('type'), 'lxc'), @@ -779,7 +779,7 @@ class LibvirtConnTestCase(test.TestCase): network_info = _fake_network_info(self.stubs, 1) xml = conn.to_xml(instance_ref, network_info) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) for i, (check, expected_result) in enumerate(checks): self.assertEqual(check(tree), @@ -795,7 +795,7 @@ class LibvirtConnTestCase(test.TestCase): xml = connection.LibvirtConnection(True).to_xml(instance_ref, network_info, image_meta) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) self.assertEqual(tree.find('./devices/disk').get('device'), device_type) self.assertEqual(tree.find('./devices/disk/target').get('bus'), bus) @@ -808,7 +808,7 @@ class LibvirtConnTestCase(test.TestCase): xml = connection.LibvirtConnection(True).to_xml(instance_ref, network_info, image_meta) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) self.assertEqual(tree.find('./uuid').text, instance_ref['uuid']) @@ -894,7 +894,7 @@ class LibvirtConnTestCase(test.TestCase): network_info = _fake_network_info(self.stubs, 1) xml = conn.to_xml(instance_ref, network_info, None, rescue) - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) for i, (check, expected_result) in enumerate(checks): self.assertEqual(check(tree), expected_result, @@ -1352,7 +1352,7 @@ class NWFilterFakes: def undefine(self): del self.parent.filters[self.name] pass - tree = xml_to_tree(xml) + tree = ElementTree.fromstring(xml) name = tree.get('name') if name not in self.filters: self.filters[name] = FakeNWFilterInternal(self, name) @@ -1772,7 +1772,7 @@ class NWFilterTestCase(test.TestCase): self.recursive_depends[f] = [] def _filterDefineXMLMock(xml): - dom = xml_to_dom(xml) + dom = minidom.parseString(xml) name = dom.firstChild.getAttribute('name') self.recursive_depends[name] = [] for f in dom.getElementsByTagName('filterref'): diff --git a/nova/tests/test_libvirt_vif.py b/nova/tests/test_libvirt_vif.py index 8e0d6627b..f8d924f48 100644 --- a/nova/tests/test_libvirt_vif.py +++ b/nova/tests/test_libvirt_vif.py @@ -20,12 +20,8 @@ from nova import flags from nova import test from nova import utils from nova.virt import firewall -from nova.virt import vif +from nova.virt.libvirt import vif from nova.virt.libvirt import connection -from nova.virt.libvirt.vif import LibvirtBridgeDriver, \ - LibvirtOpenVswitchDriver, \ - LibvirtOpenVswitchVirtualPortDriver, \ - QuantumLinuxBridgeVIFDriver FLAGS = flags.FLAGS @@ -101,7 +97,7 @@ class LibvirtVifTestCase(test.TestCase): return xml def test_bridge_driver(self): - d = LibvirtBridgeDriver() + d = vif.LibvirtBridgeDriver() xml = self._get_instance_xml(d, 'bridge') doc = ElementTree.fromstring(xml) @@ -117,7 +113,7 @@ class LibvirtVifTestCase(test.TestCase): d.unplug(None, self.net, self.mapping) def test_ovs_ethernet_driver(self): - d = LibvirtOpenVswitchDriver() + d = vif.LibvirtOpenVswitchDriver() xml = self._get_instance_xml(d, 'ethernet') doc = ElementTree.fromstring(xml) @@ -135,7 +131,7 @@ class LibvirtVifTestCase(test.TestCase): d.unplug(None, self.net, self.mapping) def test_ovs_virtualport_driver(self): - d = LibvirtOpenVswitchVirtualPortDriver() + d = vif.LibvirtOpenVswitchVirtualPortDriver() xml = self._get_instance_xml(d, 'ovs_virtualport') doc = ElementTree.fromstring(xml) @@ -161,7 +157,7 @@ class LibvirtVifTestCase(test.TestCase): d.unplug(None, self.net, self.mapping) def test_quantum_bridge_ethernet_driver(self): - d = QuantumLinuxBridgeVIFDriver() + d = vif.QuantumLinuxBridgeVIFDriver() xml = self._get_instance_xml(d, 'ethernet') doc = ElementTree.fromstring(xml) diff --git a/nova/tests/test_migrations.py b/nova/tests/test_migrations.py index 451267abe..b9d3edb95 100644 --- a/nova/tests/test_migrations.py +++ b/nova/tests/test_migrations.py @@ -33,7 +33,7 @@ import urlparse import migrate from migrate.versioning import util as migrate_util -from sqlalchemy import create_engine +import sqlalchemy import nova.db.sqlalchemy.migrate_repo from nova import log as logging @@ -68,7 +68,7 @@ if USE_MIGRATE_PATCH: # NOTE(jkoelker) Delay importing migrate until we are patched from migrate.versioning import api as migration_api -from migrate.versioning.repository import Repository +from migrate.versioning import repository class TestMigrations(unittest.TestCase): @@ -82,7 +82,8 @@ class TestMigrations(unittest.TestCase): CONFIG_FILE_PATH = os.environ.get('NOVA_TEST_MIGRATIONS_CONF', DEFAULT_CONFIG_FILE) MIGRATE_FILE = nova.db.sqlalchemy.migrate_repo.__file__ - REPOSITORY = Repository(os.path.abspath(os.path.dirname(MIGRATE_FILE))) + REPOSITORY = repository.Repository( + os.path.abspath(os.path.dirname(MIGRATE_FILE))) def setUp(self): super(TestMigrations, self).setUp() @@ -108,7 +109,7 @@ class TestMigrations(unittest.TestCase): self.engines = {} for key, value in TestMigrations.TEST_DATABASES.items(): - self.engines[key] = create_engine(value) + self.engines[key] = sqlalchemy.create_engine(value) # We start each test case with a completely blank slate. self._reset_databases() diff --git a/nova/tests/test_netapp.py b/nova/tests/test_netapp.py index e2d462fe6..01dc1aa47 100644 --- a/nova/tests/test_netapp.py +++ b/nova/tests/test_netapp.py @@ -27,7 +27,7 @@ from lxml import etree from nova import log as logging from nova import test -from nova.volume.netapp import NetAppISCSIDriver +from nova.volume import netapp LOG = logging.getLogger("nova.volume.driver") @@ -898,7 +898,7 @@ class NetAppDriverTestCase(test.TestCase): def setUp(self): super(NetAppDriverTestCase, self).setUp() - driver = NetAppISCSIDriver() + driver = netapp.NetAppISCSIDriver() self.stubs.Set(httplib, 'HTTPConnection', FakeHTTPConnection) driver._create_client('http://localhost:8088/dfm.wsdl', 'root', 'password', 'localhost', 8088) diff --git a/nova/tests/test_notifier.py b/nova/tests/test_notifier.py index 29c5dd080..c079a95d5 100644 --- a/nova/tests/test_notifier.py +++ b/nova/tests/test_notifier.py @@ -14,10 +14,9 @@ # under the License. import nova -import nova.notifier.no_op_notifier from nova import log -import nova.notifier.api -from nova.notifier.api import notify +import nova.notifier.no_op_notifier +from nova.notifier import api as notifier_api from nova import test @@ -36,7 +35,7 @@ class NotifierTestCase(test.TestCase): self.stubs.Set(nova.notifier.no_op_notifier, 'notify', mock_notify) - notify('publisher_id', 'event_type', + notifier_api.notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3)) self.assertEqual(self.notify_called, True) @@ -56,7 +55,7 @@ class NotifierTestCase(test.TestCase): self.stubs.Set(nova.notifier.no_op_notifier, 'notify', message_assert) - notify('publisher_id', 'event_type', + notifier_api.notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3)) def test_send_rabbit_notification(self): @@ -68,14 +67,14 @@ class NotifierTestCase(test.TestCase): self.mock_notify = True self.stubs.Set(nova.rpc, 'notify', mock_notify) - notify('publisher_id', 'event_type', + notifier_api.notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3)) self.assertEqual(self.mock_notify, True) def test_invalid_priority(self): self.assertRaises(nova.notifier.api.BadPriorityException, - notify, 'publisher_id', + notifier_api.notify, 'publisher_id', 'event_type', 'not a priority', dict(a=3)) def test_rabbit_priority_queue(self): @@ -90,7 +89,7 @@ class NotifierTestCase(test.TestCase): self.test_topic = topic self.stubs.Set(nova.rpc, 'notify', mock_notify) - notify('publisher_id', 'event_type', 'DEBUG', dict(a=3)) + notifier_api.notify('publisher_id', 'event_type', 'DEBUG', dict(a=3)) self.assertEqual(self.test_topic, 'testnotify.debug') def test_error_notification(self): diff --git a/nova/tests/test_quantum.py b/nova/tests/test_quantum.py index 14547afcb..de7ef501d 100644 --- a/nova/tests/test_quantum.py +++ b/nova/tests/test_quantum.py @@ -20,7 +20,7 @@ import mox from nova import context from nova import db from nova.db.sqlalchemy import models -from nova.db.sqlalchemy.session import get_session +from nova.db.sqlalchemy import session as sql_session from nova import exception from nova import flags from nova import log as logging @@ -198,7 +198,7 @@ class QuantumNovaTestCase(test.TestCase): # habit of of creating fixed IPs and not cleaning up, which # can confuse these tests, so we remove all existing fixed # ips before starting. - session = get_session() + session = sql_session.get_session() result = session.query(models.FixedIp).all() with session.begin(): for fip_ref in result: diff --git a/nova/tests/test_volume_types.py b/nova/tests/test_volume_types.py index ce7c77b2e..b1b62dea0 100644 --- a/nova/tests/test_volume_types.py +++ b/nova/tests/test_volume_types.py @@ -24,7 +24,7 @@ from nova import flags from nova import log as logging from nova import test from nova.volume import volume_types -from nova.db.sqlalchemy.session import get_session +from nova.db.sqlalchemy import session as sql_session from nova.db.sqlalchemy import models FLAGS = flags.FLAGS @@ -75,7 +75,7 @@ class VolumeTypeTestCase(test.TestCase): def test_get_all_volume_types(self): """Ensures that all volume types can be retrieved""" - session = get_session() + session = sql_session.get_session() total_volume_types = session.query(models.VolumeTypes).count() vol_types = volume_types.get_all_types(self.ctxt) self.assertEqual(total_volume_types, len(vol_types)) diff --git a/nova/tests/test_vsa.py b/nova/tests/test_vsa.py index f3c4c421b..cfc57d11c 100644 --- a/nova/tests/test_vsa.py +++ b/nova/tests/test_vsa.py @@ -36,7 +36,7 @@ class VsaTestCase(test.TestCase): def setUp(self): super(VsaTestCase, self).setUp() - self.vsa_api = vsa.API() + self.vsa_api = vsa.api.API() self.flags(quota_volumes=100, quota_gigabytes=10000) diff --git a/nova/tests/test_vsa_volumes.py b/nova/tests/test_vsa_volumes.py index 2d898ec1e..7f5a70d3a 100644 --- a/nova/tests/test_vsa_volumes.py +++ b/nova/tests/test_vsa_volumes.py @@ -15,7 +15,7 @@ from nova import exception from nova import flags -from nova import vsa +from nova.vsa import api as vsa_api from nova import volume from nova import context from nova import test @@ -30,7 +30,7 @@ class VsaVolumesTestCase(test.TestCase): def setUp(self): super(VsaVolumesTestCase, self).setUp() - self.vsa_api = vsa.API() + self.vsa_api = vsa_api.API() self.volume_api = volume.API() self.context = context.get_admin_context() diff --git a/nova/vsa/__init__.py b/nova/vsa/__init__.py index 09162e006..8b6ff0457 100644 --- a/nova/vsa/__init__.py +++ b/nova/vsa/__init__.py @@ -14,5 +14,3 @@ # 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 nova.vsa.api import API diff --git a/nova/vsa/manager.py b/nova/vsa/manager.py index b25678aae..1868030f1 100644 --- a/nova/vsa/manager.py +++ b/nova/vsa/manager.py @@ -29,11 +29,10 @@ from nova import log as logging from nova import manager from nova.openstack.common import cfg from nova import volume -from nova import vsa from nova import utils from nova.compute import instance_types from nova.vsa import utils as vsa_utils -from nova.vsa.api import VsaState +from nova.vsa import api as vsa_api vsa_driver_opt = cfg.StrOpt('vsa_driver', default='nova.vsa.connection.get_connection', @@ -56,7 +55,7 @@ class VsaManager(manager.SchedulerDependentManager): self.compute_api = compute.API() self.volume_api = volume.API() - self.vsa_api = vsa.API() + self.vsa_api = vsa_api.API() if FLAGS.vsa_ec2_user_id is None or FLAGS.vsa_ec2_access_key is None: raise exception.VSANovaAccessParamNotFound() @@ -122,9 +121,9 @@ class VsaManager(manager.SchedulerDependentManager): """Start VCs for VSA """ vsa_id = vsa['id'] - if vsa['status'] == VsaState.CREATING: + if vsa['status'] == vsa_api.VsaState.CREATING: self.vsa_api.update_vsa_status(context, vsa_id, - VsaState.LAUNCHING) + vsa_api.VsaState.LAUNCHING) else: return @@ -153,7 +152,7 @@ class VsaManager(manager.SchedulerDependentManager): LOG.info(_("VSA ID %(vsa_id)d: Delete all BE volumes"), locals()) self.vsa_api.delete_vsa_volumes(context, vsa_id, "BE", True) self.vsa_api.update_vsa_status(context, vsa_id, - VsaState.FAILED) + vsa_api.VsaState.FAILED) return # create user-data record for VC @@ -179,4 +178,4 @@ class VsaManager(manager.SchedulerDependentManager): metadata=dict(vsa_id=str(vsa_id))) self.vsa_api.update_vsa_status(context, vsa_id, - VsaState.CREATED) + vsa_api.VsaState.CREATED) diff --git a/setup.py b/setup.py index 6a876e6d1..4291c2d60 100644 --- a/setup.py +++ b/setup.py @@ -19,18 +19,16 @@ import glob import os -from setuptools import find_packages - -from setuptools import setup +import setuptools from nova import version nova_cmdclass = {} try: - from sphinx.setup_command import BuildDoc + from sphinx import setup_command - class local_BuildDoc(BuildDoc): + class local_BuildDoc(setup_command.BuildDoc): def run(self): for builder in ['html', 'man']: self.builder = builder @@ -55,14 +53,14 @@ def find_data_files(destdir, srcdir): return package_data -setup(name='nova', +setuptools.setup(name='nova', version=version.canonical_version_string(), description='cloud computing fabric controller', author='OpenStack', author_email='nova@lists.launchpad.net', url='http://www.openstack.org/', cmdclass=nova_cmdclass, - packages=find_packages(exclude=['bin', 'smoketests']), + packages=setuptools.find_packages(exclude=['bin', 'smoketests']), include_package_data=True, test_suite='nose.collector', scripts=['bin/clear_rabbit_queues',