resolve pylint warnings
This commit is contained in:
@@ -44,7 +44,6 @@ class ZoneScheduler(driver.Scheduler):
|
|||||||
if self.service_is_up(service)
|
if self.service_is_up(service)
|
||||||
and service.availability_zone == zone]
|
and service.availability_zone == zone]
|
||||||
|
|
||||||
|
|
||||||
def schedule(self, context, topic, *_args, **_kwargs):
|
def schedule(self, context, topic, *_args, **_kwargs):
|
||||||
"""Picks a host that is up at random in selected
|
"""Picks a host that is up at random in selected
|
||||||
availability zone (if defined).
|
availability zone (if defined).
|
||||||
@@ -55,4 +54,3 @@ class ZoneScheduler(driver.Scheduler):
|
|||||||
if not hosts:
|
if not hosts:
|
||||||
raise driver.NoValidHost(_("No hosts found"))
|
raise driver.NoValidHost(_("No hosts found"))
|
||||||
return hosts[int(random.random() * len(hosts))]
|
return hosts[int(random.random() * len(hosts))]
|
||||||
|
|
||||||
|
|||||||
@@ -135,12 +135,12 @@ class CloudTestCase(test.TestCase):
|
|||||||
|
|
||||||
def test_describe_availability_zones(self):
|
def test_describe_availability_zones(self):
|
||||||
"""Makes sure describe_availability_zones works and filters results."""
|
"""Makes sure describe_availability_zones works and filters results."""
|
||||||
service1 = db.service_create(self.context, {'host': 'host1_describe_zones',
|
service1 = db.service_create(self.context, {'host': 'host1_zones',
|
||||||
'binary': "nova-compute",
|
'binary': "nova-compute",
|
||||||
'topic': 'compute',
|
'topic': 'compute',
|
||||||
'report_count': 0,
|
'report_count': 0,
|
||||||
'availability_zone': "zone1"})
|
'availability_zone': "zone1"})
|
||||||
service2 = db.service_create(self.context, {'host': 'host2_describe_zones',
|
service2 = db.service_create(self.context, {'host': 'host2_zones',
|
||||||
'binary': "nova-compute",
|
'binary': "nova-compute",
|
||||||
'topic': 'compute',
|
'topic': 'compute',
|
||||||
'report_count': 0,
|
'report_count': 0,
|
||||||
@@ -150,15 +150,16 @@ class CloudTestCase(test.TestCase):
|
|||||||
db.service_destroy(self.context, service1['id'])
|
db.service_destroy(self.context, service1['id'])
|
||||||
db.service_destroy(self.context, service2['id'])
|
db.service_destroy(self.context, service2['id'])
|
||||||
|
|
||||||
|
|
||||||
def test_describe_instances(self):
|
def test_describe_instances(self):
|
||||||
"""Makes sure describe_instances works and filters results."""
|
"""Makes sure describe_instances works and filters results."""
|
||||||
inst1 = db.instance_create(self.context, {'reservation_id': 'a', 'host': 'host1'})
|
inst1 = db.instance_create(self.context, {'reservation_id': 'a',
|
||||||
inst2 = db.instance_create(self.context, {'reservation_id': 'a', 'host': 'host2'})
|
'host': 'host1'})
|
||||||
compute1 = db.service_create(self.context, {'host': 'host1',
|
inst2 = db.instance_create(self.context, {'reservation_id': 'a',
|
||||||
|
'host': 'host2'})
|
||||||
|
comp1 = db.service_create(self.context, {'host': 'host1',
|
||||||
'availability_zone': 'zone1',
|
'availability_zone': 'zone1',
|
||||||
'topic': "compute"})
|
'topic': "compute"})
|
||||||
compute2 = db.service_create(self.context, {'host': 'host2',
|
comp2 = db.service_create(self.context, {'host': 'host2',
|
||||||
'availability_zone': 'zone2',
|
'availability_zone': 'zone2',
|
||||||
'topic': "compute"})
|
'topic': "compute"})
|
||||||
result = self.cloud.describe_instances(self.context)
|
result = self.cloud.describe_instances(self.context)
|
||||||
@@ -171,13 +172,12 @@ class CloudTestCase(test.TestCase):
|
|||||||
self.assertEqual(len(result['instancesSet']), 1)
|
self.assertEqual(len(result['instancesSet']), 1)
|
||||||
self.assertEqual(result['instancesSet'][0]['instanceId'],
|
self.assertEqual(result['instancesSet'][0]['instanceId'],
|
||||||
instance_id)
|
instance_id)
|
||||||
self.assertEqual(result['instancesSet'][0]\
|
self.assertEqual(result['instancesSet'][0]
|
||||||
['placement']['availabilityZone'], 'zone2')
|
['placement']['availabilityZone'], 'zone2')
|
||||||
db.instance_destroy(self.context, inst1['id'])
|
db.instance_destroy(self.context, inst1['id'])
|
||||||
db.instance_destroy(self.context, inst2['id'])
|
db.instance_destroy(self.context, inst2['id'])
|
||||||
db.service_destroy(self.context, compute1['id'])
|
db.service_destroy(self.context, comp1['id'])
|
||||||
db.service_destroy(self.context, compute2['id'])
|
db.service_destroy(self.context, comp2['id'])
|
||||||
|
|
||||||
|
|
||||||
def test_console_output(self):
|
def test_console_output(self):
|
||||||
image_id = FLAGS.default_image
|
image_id = FLAGS.default_image
|
||||||
@@ -257,20 +257,18 @@ class CloudTestCase(test.TestCase):
|
|||||||
LOG.debug(_("Terminating instance %s"), instance_id)
|
LOG.debug(_("Terminating instance %s"), instance_id)
|
||||||
rv = self.compute.terminate_instance(instance_id)
|
rv = self.compute.terminate_instance(instance_id)
|
||||||
|
|
||||||
|
|
||||||
def test_describe_instances(self):
|
def test_describe_instances(self):
|
||||||
"""Makes sure describe_instances works."""
|
"""Makes sure describe_instances works."""
|
||||||
instance1 = db.instance_create(self.context, {'host': 'host2'})
|
instance1 = db.instance_create(self.context, {'host': 'host2'})
|
||||||
service1 = db.service_create(self.context, {'host': 'host2',
|
comp1 = db.service_create(self.context, {'host': 'host2',
|
||||||
'availability_zone': 'zone1',
|
'availability_zone': 'zone1',
|
||||||
'topic': "compute"})
|
'topic': "compute"})
|
||||||
result = self.cloud.describe_instances(self.context)
|
result = self.cloud.describe_instances(self.context)
|
||||||
self.assertEqual(result['reservationSet'][0]\
|
self.assertEqual(result['reservationSet'][0]
|
||||||
['instancesSet'][0]\
|
['instancesSet'][0]
|
||||||
['placement']['availabilityZone'], 'zone1')
|
['placement']['availabilityZone'], 'zone1')
|
||||||
db.instance_destroy(self.context, instance1['id'])
|
db.instance_destroy(self.context, instance1['id'])
|
||||||
db.service_destroy(self.context, service1['id'])
|
db.service_destroy(self.context, comp1['id'])
|
||||||
|
|
||||||
|
|
||||||
def test_instance_update_state(self):
|
def test_instance_update_state(self):
|
||||||
def instance(num):
|
def instance(num):
|
||||||
@@ -321,7 +319,6 @@ class CloudTestCase(test.TestCase):
|
|||||||
# data = self.cloud.get_metadata(instance(i)['private_dns_name'])
|
# data = self.cloud.get_metadata(instance(i)['private_dns_name'])
|
||||||
# self.assert_(data['meta-data']['ami-id'] == 'ami-%s' % i)
|
# self.assert_(data['meta-data']['ami-id'] == 'ami-%s' % i)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _fake_set_image_description(ctxt, image_id, description):
|
def _fake_set_image_description(ctxt, image_id, description):
|
||||||
from nova.objectstore import handler
|
from nova.objectstore import handler
|
||||||
|
|||||||
@@ -76,47 +76,6 @@ class SchedulerTestCase(test.TestCase):
|
|||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
scheduler.named_method(ctxt, 'topic', num=7)
|
scheduler.named_method(ctxt, 'topic', num=7)
|
||||||
|
|
||||||
class ZoneSchedulerTestCase(test.TestCase):
|
|
||||||
"""Test case for zone scheduler"""
|
|
||||||
def setUp(self):
|
|
||||||
super(ZoneSchedulerTestCase, self).setUp()
|
|
||||||
self.flags(scheduler_driver='nova.scheduler.zone.ZoneScheduler')
|
|
||||||
|
|
||||||
def _create_service_model(self, **kwargs):
|
|
||||||
service = db.sqlalchemy.models.Service()
|
|
||||||
service.host = kwargs['host']
|
|
||||||
service.disabled = False
|
|
||||||
service.deleted = False
|
|
||||||
service.report_count = 0
|
|
||||||
service.binary = 'nova-compute'
|
|
||||||
service.topic = 'compute'
|
|
||||||
service.id = kwargs['id']
|
|
||||||
service.availability_zone = kwargs['zone']
|
|
||||||
service.created_at = datetime.datetime.utcnow()
|
|
||||||
return service
|
|
||||||
|
|
||||||
|
|
||||||
def test_with_two_zones(self):
|
|
||||||
scheduler = manager.SchedulerManager()
|
|
||||||
ctxt = context.get_admin_context()
|
|
||||||
service_list = [
|
|
||||||
self._create_service_model(id=1, host='host1', zone='zone1'),
|
|
||||||
self._create_service_model(id=2, host='host2', zone='zone2'),
|
|
||||||
self._create_service_model(id=3, host='host3', zone='zone2'),
|
|
||||||
self._create_service_model(id=4, host='host4', zone='zone2'),
|
|
||||||
self._create_service_model(id=5, host='host5', zone='zone2')
|
|
||||||
]
|
|
||||||
self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
|
|
||||||
db.service_get_all_by_topic(IgnoreArg(), IgnoreArg()).AndReturn(service_list)
|
|
||||||
self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
|
|
||||||
rpc.cast(ctxt,
|
|
||||||
'compute.host1',
|
|
||||||
{'method': 'run_instance',
|
|
||||||
'args':{'instance_id': 'i-ffffffff',
|
|
||||||
'availability_zone': 'zone1'}})
|
|
||||||
self.mox.ReplayAll()
|
|
||||||
scheduler.run_instance(ctxt, 'compute', instance_id='i-ffffffff', availability_zone='zone1')
|
|
||||||
|
|
||||||
|
|
||||||
class ZoneSchedulerTestCase(test.TestCase):
|
class ZoneSchedulerTestCase(test.TestCase):
|
||||||
"""Test case for zone scheduler"""
|
"""Test case for zone scheduler"""
|
||||||
@@ -137,19 +96,27 @@ class ZoneSchedulerTestCase(test.TestCase):
|
|||||||
service.created_at = datetime.datetime.utcnow()
|
service.created_at = datetime.datetime.utcnow()
|
||||||
return service
|
return service
|
||||||
|
|
||||||
|
|
||||||
def test_with_two_zones(self):
|
def test_with_two_zones(self):
|
||||||
scheduler = manager.SchedulerManager()
|
scheduler = manager.SchedulerManager()
|
||||||
ctxt = context.get_admin_context()
|
ctxt = context.get_admin_context()
|
||||||
service_list = [
|
service_list = [self._create_service_model(id=1,
|
||||||
self._create_service_model(id=1, host='host1', zone='zone1'),
|
host='host1',
|
||||||
self._create_service_model(id=2, host='host2', zone='zone2'),
|
zone='zone1'),
|
||||||
self._create_service_model(id=3, host='host3', zone='zone2'),
|
self._create_service_model(id=2,
|
||||||
self._create_service_model(id=4, host='host4', zone='zone2'),
|
host='host2',
|
||||||
self._create_service_model(id=5, host='host5', zone='zone2')
|
zone='zone2'),
|
||||||
]
|
self._create_service_model(id=3,
|
||||||
|
host='host3',
|
||||||
|
zone='zone2'),
|
||||||
|
self._create_service_model(id=4,
|
||||||
|
host='host4',
|
||||||
|
zone='zone2'),
|
||||||
|
self._create_service_model(id=5,
|
||||||
|
host='host5',
|
||||||
|
zone='zone2')]
|
||||||
self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
|
self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
|
||||||
db.service_get_all_by_topic(IgnoreArg(), IgnoreArg()).AndReturn(service_list)
|
arg = IgnoreArg()
|
||||||
|
db.service_get_all_by_topic(arg, arg).AndReturn(service_list)
|
||||||
self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
|
self.mox.StubOutWithMock(rpc, 'cast', use_mock_anything=True)
|
||||||
rpc.cast(ctxt,
|
rpc.cast(ctxt,
|
||||||
'compute.host1',
|
'compute.host1',
|
||||||
@@ -157,7 +124,10 @@ class ZoneSchedulerTestCase(test.TestCase):
|
|||||||
'args': {'instance_id': 'i-ffffffff',
|
'args': {'instance_id': 'i-ffffffff',
|
||||||
'availability_zone': 'zone1'}})
|
'availability_zone': 'zone1'}})
|
||||||
self.mox.ReplayAll()
|
self.mox.ReplayAll()
|
||||||
scheduler.run_instance(ctxt, 'compute', instance_id='i-ffffffff', availability_zone='zone1')
|
scheduler.run_instance(ctxt,
|
||||||
|
'compute',
|
||||||
|
instance_id='i-ffffffff',
|
||||||
|
availability_zone='zone1')
|
||||||
|
|
||||||
|
|
||||||
class SimpleDriverTestCase(test.TestCase):
|
class SimpleDriverTestCase(test.TestCase):
|
||||||
|
|||||||
Reference in New Issue
Block a user