* Updated readme file with installation of suds-0.4 through easy_install.
* Removed pass functions * Fixed pep8 errors * Few bug fixes and other commits Also rebased this branch to nova revision 761
This commit is contained in:
2
.mailmap
2
.mailmap
@@ -15,10 +15,12 @@
|
|||||||
<corywright@gmail.com> <cory.wright@rackspace.com>
|
<corywright@gmail.com> <cory.wright@rackspace.com>
|
||||||
<devin.carlen@gmail.com> <devcamcar@illian.local>
|
<devin.carlen@gmail.com> <devcamcar@illian.local>
|
||||||
<ewan.mellor@citrix.com> <emellor@silver>
|
<ewan.mellor@citrix.com> <emellor@silver>
|
||||||
|
<itoumsn@nttdata.co.jp> <itoumsn@shayol>
|
||||||
<jaypipes@gmail.com> <jpipes@serialcoder>
|
<jaypipes@gmail.com> <jpipes@serialcoder>
|
||||||
<jmckenty@gmail.com> <jmckenty@joshua-mckentys-macbook-pro.local>
|
<jmckenty@gmail.com> <jmckenty@joshua-mckentys-macbook-pro.local>
|
||||||
<jmckenty@gmail.com> <jmckenty@yyj-dhcp171.corp.flock.com>
|
<jmckenty@gmail.com> <jmckenty@yyj-dhcp171.corp.flock.com>
|
||||||
<jmckenty@gmail.com> <joshua.mckenty@nasa.gov>
|
<jmckenty@gmail.com> <joshua.mckenty@nasa.gov>
|
||||||
|
<josh@jk0.org> <josh.kearney@rackspace.com>
|
||||||
<justin@fathomdb.com> <justinsb@justinsb-desktop>
|
<justin@fathomdb.com> <justinsb@justinsb-desktop>
|
||||||
<justin@fathomdb.com> <superstack@superstack.org>
|
<justin@fathomdb.com> <superstack@superstack.org>
|
||||||
<masumotok@nttdata.co.jp> Masumoto<masumotok@nttdata.co.jp>
|
<masumotok@nttdata.co.jp> Masumoto<masumotok@nttdata.co.jp>
|
||||||
|
|||||||
3
Authors
3
Authors
@@ -31,7 +31,7 @@ John Dewey <john@dewey.ws>
|
|||||||
Jonathan Bryce <jbryce@jbryce.com>
|
Jonathan Bryce <jbryce@jbryce.com>
|
||||||
Jordan Rinke <jordan@openstack.org>
|
Jordan Rinke <jordan@openstack.org>
|
||||||
Josh Durgin <joshd@hq.newdream.net>
|
Josh Durgin <joshd@hq.newdream.net>
|
||||||
Josh Kearney <josh.kearney@rackspace.com>
|
Josh Kearney <josh@jk0.org>
|
||||||
Joshua McKenty <jmckenty@gmail.com>
|
Joshua McKenty <jmckenty@gmail.com>
|
||||||
Justin Santa Barbara <justin@fathomdb.com>
|
Justin Santa Barbara <justin@fathomdb.com>
|
||||||
Kei Masumoto <masumotok@nttdata.co.jp>
|
Kei Masumoto <masumotok@nttdata.co.jp>
|
||||||
@@ -39,6 +39,7 @@ Ken Pepple <ken.pepple@gmail.com>
|
|||||||
Kevin L. Mitchell <kevin.mitchell@rackspace.com>
|
Kevin L. Mitchell <kevin.mitchell@rackspace.com>
|
||||||
Koji Iida <iida.koji@lab.ntt.co.jp>
|
Koji Iida <iida.koji@lab.ntt.co.jp>
|
||||||
Lorin Hochstein <lorin@isi.edu>
|
Lorin Hochstein <lorin@isi.edu>
|
||||||
|
Masanori Itoh <itoumsn@nttdata.co.jp>
|
||||||
Matt Dietz <matt.dietz@rackspace.com>
|
Matt Dietz <matt.dietz@rackspace.com>
|
||||||
Michael Gundlach <michael.gundlach@rackspace.com>
|
Michael Gundlach <michael.gundlach@rackspace.com>
|
||||||
Monsyne Dragon <mdragon@rackspace.com>
|
Monsyne Dragon <mdragon@rackspace.com>
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ from nova import utils
|
|||||||
from nova.api.ec2.cloud import ec2_id_to_id
|
from nova.api.ec2.cloud import ec2_id_to_id
|
||||||
from nova.auth import manager
|
from nova.auth import manager
|
||||||
from nova.cloudpipe import pipelib
|
from nova.cloudpipe import pipelib
|
||||||
|
from nova.compute import instance_types
|
||||||
from nova.db import migration
|
from nova.db import migration
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
@@ -661,6 +662,79 @@ class VolumeCommands(object):
|
|||||||
"mountpoint": volume['mountpoint']}})
|
"mountpoint": volume['mountpoint']}})
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceTypeCommands(object):
|
||||||
|
"""Class for managing instance types / flavors."""
|
||||||
|
|
||||||
|
def _print_instance_types(self, n, val):
|
||||||
|
deleted = ('', ', inactive')[val["deleted"] == 1]
|
||||||
|
print ("%s: Memory: %sMB, VCPUS: %s, Storage: %sGB, FlavorID: %s, "
|
||||||
|
"Swap: %sGB, RXTX Quota: %sGB, RXTX Cap: %sMB%s") % (
|
||||||
|
n, val["memory_mb"], val["vcpus"], val["local_gb"],
|
||||||
|
val["flavorid"], val["swap"], val["rxtx_quota"],
|
||||||
|
val["rxtx_cap"], deleted)
|
||||||
|
|
||||||
|
def create(self, name, memory, vcpus, local_gb, flavorid,
|
||||||
|
swap=0, rxtx_quota=0, rxtx_cap=0):
|
||||||
|
"""Creates instance types / flavors
|
||||||
|
arguments: name memory vcpus local_gb flavorid [swap] [rxtx_quota]
|
||||||
|
[rxtx_cap]
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
instance_types.create(name, memory, vcpus, local_gb,
|
||||||
|
flavorid, swap, rxtx_quota, rxtx_cap)
|
||||||
|
except exception.InvalidInputException:
|
||||||
|
print "Must supply valid parameters to create instance type"
|
||||||
|
print e
|
||||||
|
sys.exit(1)
|
||||||
|
except exception.DBError, e:
|
||||||
|
print "DB Error: %s" % e
|
||||||
|
sys.exit(2)
|
||||||
|
except:
|
||||||
|
print "Unknown error"
|
||||||
|
sys.exit(3)
|
||||||
|
else:
|
||||||
|
print "%s created" % name
|
||||||
|
|
||||||
|
def delete(self, name, purge=None):
|
||||||
|
"""Marks instance types / flavors as deleted
|
||||||
|
arguments: name"""
|
||||||
|
try:
|
||||||
|
if purge == "--purge":
|
||||||
|
instance_types.purge(name)
|
||||||
|
verb = "purged"
|
||||||
|
else:
|
||||||
|
instance_types.destroy(name)
|
||||||
|
verb = "deleted"
|
||||||
|
except exception.ApiError:
|
||||||
|
print "Valid instance type name is required"
|
||||||
|
sys.exit(1)
|
||||||
|
except exception.DBError, e:
|
||||||
|
print "DB Error: %s" % e
|
||||||
|
sys.exit(2)
|
||||||
|
except:
|
||||||
|
sys.exit(3)
|
||||||
|
else:
|
||||||
|
print "%s %s" % (name, verb)
|
||||||
|
|
||||||
|
def list(self, name=None):
|
||||||
|
"""Lists all active or specific instance types / flavors
|
||||||
|
arguments: [name]"""
|
||||||
|
try:
|
||||||
|
if name == None:
|
||||||
|
inst_types = instance_types.get_all_types()
|
||||||
|
elif name == "--all":
|
||||||
|
inst_types = instance_types.get_all_types(1)
|
||||||
|
else:
|
||||||
|
inst_types = instance_types.get_instance_type(name)
|
||||||
|
except exception.DBError, e:
|
||||||
|
_db_error(e)
|
||||||
|
if isinstance(inst_types.values()[0], dict):
|
||||||
|
for k, v in inst_types.iteritems():
|
||||||
|
self._print_instance_types(k, v)
|
||||||
|
else:
|
||||||
|
self._print_instance_types(name, inst_types)
|
||||||
|
|
||||||
|
|
||||||
CATEGORIES = [
|
CATEGORIES = [
|
||||||
('user', UserCommands),
|
('user', UserCommands),
|
||||||
('project', ProjectCommands),
|
('project', ProjectCommands),
|
||||||
@@ -673,7 +747,9 @@ CATEGORIES = [
|
|||||||
('service', ServiceCommands),
|
('service', ServiceCommands),
|
||||||
('log', LogCommands),
|
('log', LogCommands),
|
||||||
('db', DbCommands),
|
('db', DbCommands),
|
||||||
('volume', VolumeCommands)]
|
('volume', VolumeCommands),
|
||||||
|
('instance_type', InstanceTypeCommands),
|
||||||
|
('flavor', InstanceTypeCommands)]
|
||||||
|
|
||||||
|
|
||||||
def lazy_match(name, key_value_tuples):
|
def lazy_match(name, key_value_tuples):
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ class CloudTestCase(test.TestCase):
|
|||||||
self._create_key('test1')
|
self._create_key('test1')
|
||||||
self._create_key('test2')
|
self._create_key('test2')
|
||||||
result = self.cloud.describe_key_pairs(self.context)
|
result = self.cloud.describe_key_pairs(self.context)
|
||||||
keys = result["keypairsSet"]
|
keys = result["keySet"]
|
||||||
self.assertTrue(filter(lambda k: k['keyName'] == 'test1', keys))
|
self.assertTrue(filter(lambda k: k['keyName'] == 'test1', keys))
|
||||||
self.assertTrue(filter(lambda k: k['keyName'] == 'test2', keys))
|
self.assertTrue(filter(lambda k: k['keyName'] == 'test2', keys))
|
||||||
|
|
||||||
|
|||||||
86
nova/tests/test_instance_types.py
Normal file
86
nova/tests/test_instance_types.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
|
# Copyright 2011 Ken Pepple
|
||||||
|
# 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.
|
||||||
|
"""
|
||||||
|
Unit Tests for instance types code
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
|
||||||
|
from nova import context
|
||||||
|
from nova import db
|
||||||
|
from nova import exception
|
||||||
|
from nova import flags
|
||||||
|
from nova import log as logging
|
||||||
|
from nova import test
|
||||||
|
from nova import utils
|
||||||
|
from nova.compute import instance_types
|
||||||
|
from nova.db.sqlalchemy.session import get_session
|
||||||
|
from nova.db.sqlalchemy import models
|
||||||
|
|
||||||
|
FLAGS = flags.FLAGS
|
||||||
|
LOG = logging.getLogger('nova.tests.compute')
|
||||||
|
|
||||||
|
|
||||||
|
class InstanceTypeTestCase(test.TestCase):
|
||||||
|
"""Test cases for instance type code"""
|
||||||
|
def setUp(self):
|
||||||
|
super(InstanceTypeTestCase, self).setUp()
|
||||||
|
session = get_session()
|
||||||
|
max_flavorid = session.query(models.InstanceTypes).\
|
||||||
|
order_by("flavorid desc").\
|
||||||
|
first()
|
||||||
|
self.flavorid = max_flavorid["flavorid"] + 1
|
||||||
|
self.name = str(int(time.time()))
|
||||||
|
|
||||||
|
def test_instance_type_create_then_delete(self):
|
||||||
|
"""Ensure instance types can be created"""
|
||||||
|
starting_inst_list = instance_types.get_all_types()
|
||||||
|
instance_types.create(self.name, 256, 1, 120, self.flavorid)
|
||||||
|
new = instance_types.get_all_types()
|
||||||
|
self.assertNotEqual(len(starting_inst_list),
|
||||||
|
len(new),
|
||||||
|
'instance type was not created')
|
||||||
|
instance_types.destroy(self.name)
|
||||||
|
self.assertEqual(1,
|
||||||
|
instance_types.get_instance_type(self.name)["deleted"])
|
||||||
|
self.assertEqual(starting_inst_list, instance_types.get_all_types())
|
||||||
|
instance_types.purge(self.name)
|
||||||
|
self.assertEqual(len(starting_inst_list),
|
||||||
|
len(instance_types.get_all_types()),
|
||||||
|
'instance type not purged')
|
||||||
|
|
||||||
|
def test_get_all_instance_types(self):
|
||||||
|
"""Ensures that all instance types can be retrieved"""
|
||||||
|
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))
|
||||||
|
|
||||||
|
def test_invalid_create_args_should_fail(self):
|
||||||
|
"""Ensures that instance type creation fails with invalid args"""
|
||||||
|
self.assertRaises(
|
||||||
|
exception.InvalidInputException,
|
||||||
|
instance_types.create, self.name, 0, 1, 120, self.flavorid)
|
||||||
|
self.assertRaises(
|
||||||
|
exception.InvalidInputException,
|
||||||
|
instance_types.create, self.name, 256, -1, 120, self.flavorid)
|
||||||
|
self.assertRaises(
|
||||||
|
exception.InvalidInputException,
|
||||||
|
instance_types.create, self.name, 256, 1, "aa", self.flavorid)
|
||||||
|
|
||||||
|
def test_non_existant_inst_type_shouldnt_delete(self):
|
||||||
|
"""Ensures that instance type creation fails with invalid args"""
|
||||||
|
self.assertRaises(exception.ApiError,
|
||||||
|
instance_types.destroy, "sfsfsdfdfs")
|
||||||
@@ -26,7 +26,6 @@ from nova import flags
|
|||||||
from nova import test
|
from nova import test
|
||||||
from nova import utils
|
from nova import utils
|
||||||
from nova.auth import manager
|
from nova.auth import manager
|
||||||
from nova.compute import instance_types
|
|
||||||
from nova.compute import power_state
|
from nova.compute import power_state
|
||||||
from nova.tests.glance import stubs as glance_stubs
|
from nova.tests.glance import stubs as glance_stubs
|
||||||
from nova.tests.vmwareapi import db_fakes
|
from nova.tests.vmwareapi import db_fakes
|
||||||
@@ -74,7 +73,7 @@ class VMWareAPIVMTestCase(test.TestCase):
|
|||||||
'mac_address': 'aa:bb:cc:dd:ee:ff',
|
'mac_address': 'aa:bb:cc:dd:ee:ff',
|
||||||
}
|
}
|
||||||
self.instance = db.instance_create(values)
|
self.instance = db.instance_create(values)
|
||||||
self.type_data = instance_types.INSTANCE_TYPES[values['instance_type']]
|
self.type_data = db.instance_type_get_by_name(None, 'm1.large')
|
||||||
self.conn.spawn(self.instance)
|
self.conn.spawn(self.instance)
|
||||||
self._check_vm_record()
|
self._check_vm_record()
|
||||||
|
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ class XenAPIVMTestCase(test.TestCase):
|
|||||||
vm = vms[0]
|
vm = vms[0]
|
||||||
|
|
||||||
# Check that m1.large above turned into the right thing.
|
# Check that m1.large above turned into the right thing.
|
||||||
instance_type = instance_types.INSTANCE_TYPES['m1.large']
|
instance_type = db.instance_type_get_by_name(conn, 'm1.large')
|
||||||
mem_kib = long(instance_type['memory_mb']) << 10
|
mem_kib = long(instance_type['memory_mb']) << 10
|
||||||
mem_bytes = str(mem_kib << 10)
|
mem_bytes = str(mem_kib << 10)
|
||||||
vcpus = instance_type['vcpus']
|
vcpus = instance_type['vcpus']
|
||||||
|
|||||||
@@ -23,12 +23,20 @@ import time
|
|||||||
|
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import utils
|
from nova import utils
|
||||||
from nova.compute import instance_types
|
|
||||||
|
|
||||||
|
|
||||||
def stub_out_db_instance_api(stubs):
|
def stub_out_db_instance_api(stubs):
|
||||||
""" Stubs out the db API for creating Instances """
|
""" Stubs out the db API for creating Instances """
|
||||||
|
|
||||||
|
INSTANCE_TYPES = {
|
||||||
|
'm1.tiny': dict(memory_mb=512, vcpus=1, local_gb=0, flavorid=1),
|
||||||
|
'm1.small': dict(memory_mb=2048, vcpus=1, local_gb=20, flavorid=2),
|
||||||
|
'm1.medium':
|
||||||
|
dict(memory_mb=4096, vcpus=2, local_gb=40, flavorid=3),
|
||||||
|
'm1.large': dict(memory_mb=8192, vcpus=4, local_gb=80, flavorid=4),
|
||||||
|
'm1.xlarge':
|
||||||
|
dict(memory_mb=16384, vcpus=8, local_gb=160, flavorid=5)}
|
||||||
|
|
||||||
class FakeModel(object):
|
class FakeModel(object):
|
||||||
""" Stubs out for model """
|
""" Stubs out for model """
|
||||||
|
|
||||||
@@ -47,7 +55,7 @@ def stub_out_db_instance_api(stubs):
|
|||||||
def fake_instance_create(values):
|
def fake_instance_create(values):
|
||||||
""" Stubs out the db.instance_create method """
|
""" Stubs out the db.instance_create method """
|
||||||
|
|
||||||
type_data = instance_types.INSTANCE_TYPES[values['instance_type']]
|
type_data = INSTANCE_TYPES[values['instance_type']]
|
||||||
|
|
||||||
base_options = {
|
base_options = {
|
||||||
'name': values['name'],
|
'name': values['name'],
|
||||||
@@ -86,8 +94,16 @@ def stub_out_db_instance_api(stubs):
|
|||||||
""" Stubs out the db.instance_get_fixed_address method """
|
""" Stubs out the db.instance_get_fixed_address method """
|
||||||
return '10.10.10.10'
|
return '10.10.10.10'
|
||||||
|
|
||||||
|
def fake_instance_type_get_all(context, inactive=0):
|
||||||
|
return INSTANCE_TYPES
|
||||||
|
|
||||||
|
def fake_instance_type_get_by_name(context, name):
|
||||||
|
return INSTANCE_TYPES[name]
|
||||||
|
|
||||||
stubs.Set(db, 'instance_create', fake_instance_create)
|
stubs.Set(db, 'instance_create', fake_instance_create)
|
||||||
stubs.Set(db, 'network_get_by_instance', fake_network_get_by_instance)
|
stubs.Set(db, 'network_get_by_instance', fake_network_get_by_instance)
|
||||||
stubs.Set(db, 'instance_action_create', fake_instance_action_create)
|
stubs.Set(db, 'instance_action_create', fake_instance_action_create)
|
||||||
stubs.Set(db, 'instance_get_fixed_address',
|
stubs.Set(db, 'instance_get_fixed_address',
|
||||||
fake_instance_get_fixed_address)
|
fake_instance_get_fixed_address)
|
||||||
|
stubs.Set(db, 'instance_type_get_all', fake_instance_type_get_all)
|
||||||
|
stubs.Set(db, 'instance_type_get_by_name', fake_instance_type_get_by_name)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ def stubout_instance_snapshot(stubs):
|
|||||||
def fake_fetch_image(cls, session, instance_id, image, user, project,
|
def fake_fetch_image(cls, session, instance_id, image, user, project,
|
||||||
type):
|
type):
|
||||||
# Stubout wait_for_task
|
# Stubout wait_for_task
|
||||||
def fake_wait_for_task(self, id, task):
|
def fake_wait_for_task(self, task, id):
|
||||||
class FakeEvent:
|
class FakeEvent:
|
||||||
|
|
||||||
def send(self, value):
|
def send(self, value):
|
||||||
|
|||||||
Reference in New Issue
Block a user