Merge "Add new test with betamax for create flavors"

This commit is contained in:
Jenkins 2016-08-06 08:08:18 +00:00 committed by Gerrit Code Review
commit bde6ad8436
4 changed files with 2143 additions and 16 deletions

View File

@ -8,7 +8,7 @@ os-client-config>=1.17.0,!=1.19.0
requestsexceptions>=1.1.1 requestsexceptions>=1.1.1
six six
keystoneauth1>=2.8.0 keystoneauth1>=2.11.0
netifaces>=0.10.4 netifaces>=0.10.4
python-novaclient>=2.21.0,!=2.27.0,!=2.32.0 python-novaclient>=2.21.0,!=2.27.0,!=2.32.0
python-keystoneclient>=0.11.0 python-keystoneclient>=0.11.0

File diff suppressed because it is too large Load Diff

View File

@ -43,7 +43,7 @@ class TestCreateServer(base.TestCase):
Test that an exception in the novaclient create raises an exception in Test that an exception in the novaclient create raises an exception in
create_server. create_server.
""" """
with patch("shade.OpenStackCloud"): with patch("shade.OpenStackCloud.nova_client"):
config = { config = {
"servers.create.side_effect": Exception("exception"), "servers.create.side_effect": Exception("exception"),
} }
@ -57,7 +57,7 @@ class TestCreateServer(base.TestCase):
Test that an exception when attempting to get the server instance via Test that an exception when attempting to get the server instance via
the novaclient raises an exception in create_server. the novaclient raises an exception in create_server.
""" """
with patch("shade.OpenStackCloud"): with patch("shade.OpenStackCloud.nova_client"):
config = { config = {
"servers.create.return_value": Mock(status="BUILD"), "servers.create.return_value": Mock(status="BUILD"),
"servers.get.side_effect": Exception("exception") "servers.get.side_effect": Exception("exception")
@ -74,7 +74,7 @@ class TestCreateServer(base.TestCase):
""" """
build_server = fakes.FakeServer('1234', '', 'BUILD') build_server = fakes.FakeServer('1234', '', 'BUILD')
error_server = fakes.FakeServer('1234', '', 'ERROR') error_server = fakes.FakeServer('1234', '', 'ERROR')
with patch("shade.OpenStackCloud"): with patch("shade.OpenStackCloud.nova_client"):
config = { config = {
"servers.create.return_value": build_server, "servers.create.return_value": build_server,
"servers.get.return_value": error_server, "servers.get.return_value": error_server,
@ -89,7 +89,7 @@ class TestCreateServer(base.TestCase):
Test that a server error while waiting for the server to spawn Test that a server error while waiting for the server to spawn
raises an exception in create_server. raises an exception in create_server.
""" """
with patch("shade.OpenStackCloud"): with patch("shade.OpenStackCloud.nova_client"):
build_server = fakes.FakeServer('1234', '', 'BUILD') build_server = fakes.FakeServer('1234', '', 'BUILD')
error_server = fakes.FakeServer('1234', '', 'ERROR') error_server = fakes.FakeServer('1234', '', 'ERROR')
fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
@ -113,7 +113,7 @@ class TestCreateServer(base.TestCase):
Test that a timeout while waiting for the server to spawn raises an Test that a timeout while waiting for the server to spawn raises an
exception in create_server. exception in create_server.
""" """
with patch("shade.OpenStackCloud"): with patch("shade.OpenStackCloud.nova_client"):
fake_server = fakes.FakeServer('1234', '', 'BUILD') fake_server = fakes.FakeServer('1234', '', 'BUILD')
config = { config = {
"servers.create.return_value": fake_server, "servers.create.return_value": fake_server,
@ -131,7 +131,7 @@ class TestCreateServer(base.TestCase):
Test that create_server with no wait and no exception in the Test that create_server with no wait and no exception in the
novaclient create call returns the server instance. novaclient create call returns the server instance.
""" """
with patch("shade.OpenStackCloud"): with patch("shade.OpenStackCloud.nova_client"):
fake_server = fakes.FakeServer('1234', '', 'BUILD') fake_server = fakes.FakeServer('1234', '', 'BUILD')
fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',
'1.1.1.1', '2.2.2.2', '1.1.1.1', '2.2.2.2',
@ -155,7 +155,7 @@ class TestCreateServer(base.TestCase):
""" """
Test that a server with an admin_pass passed returns the password Test that a server with an admin_pass passed returns the password
""" """
with patch("shade.OpenStackCloud"): with patch("shade.OpenStackCloud.nova_client"):
fake_server = fakes.FakeServer('1234', '', 'BUILD') fake_server = fakes.FakeServer('1234', '', 'BUILD')
fake_create_server = fakes.FakeServer('1234', '', 'BUILD', fake_create_server = fakes.FakeServer('1234', '', 'BUILD',
adminPass='ooBootheiX0edoh') adminPass='ooBootheiX0edoh')
@ -265,7 +265,7 @@ class TestCreateServer(base.TestCase):
Test that create_server with a wait throws an exception if the Test that create_server with a wait throws an exception if the
server doesn't have addresses. server doesn't have addresses.
""" """
with patch("shade.OpenStackCloud"): with patch("shade.OpenStackCloud.nova_client"):
build_server = fakes.FakeServer('1234', '', 'BUILD') build_server = fakes.FakeServer('1234', '', 'BUILD')
fake_server = fakes.FakeServer('1234', '', 'ACTIVE') fake_server = fakes.FakeServer('1234', '', 'ACTIVE')
fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool', fake_floating_ip = fakes.FakeFloatingIP('1234', 'ippool',

View File

@ -16,6 +16,8 @@
import mock import mock
import shade import shade
from keystoneauth1.fixture import keystoneauth_betamax
from keystoneauth1.fixture import serializer
from shade.tests import fakes from shade.tests import fakes
from shade.tests.unit import base from shade.tests.unit import base
@ -25,16 +27,36 @@ class TestFlavors(base.TestCase):
def setUp(self): def setUp(self):
super(TestFlavors, self).setUp() super(TestFlavors, self).setUp()
@mock.patch.object(shade.OpenStackCloud, 'nova_client') def test_create_flavor(self):
def test_create_flavor(self, mock_nova): self.useFixture(keystoneauth_betamax.BetamaxFixture(
cassette_name='test_create_flavor',
cassette_library_dir=self.fixtures_directory,
record=self.record_fixtures,
serializer=serializer.YamlJsonSerializer))
old_flavors = self.op_cloud.list_flavors()
self.op_cloud.create_flavor( self.op_cloud.create_flavor(
'vanilla', 12345, 4, 100 'vanilla', 12345, 4, 100
) )
mock_nova.flavors.create.assert_called_once_with(
name='vanilla', ram=12345, vcpus=4, disk=100, # test that we have a new flavor added
flavorid='auto', ephemeral=0, swap=0, rxtx_factor=1.0, new_flavors = self.op_cloud.list_flavors()
is_public=True self.assertEquals(len(new_flavors) - len(old_flavors), 1)
)
# test that new flavor is created correctly
found = False
for flavor in new_flavors:
if flavor['name'] == 'vanilla':
found = True
break
self.assertTrue(found)
needed_keys = {'name', 'ram', 'vcpus', 'id', 'is_public', 'disk'}
if found:
# check flavor content
self.assertTrue(needed_keys.issubset(flavor.keys()))
# delete created flavor
self.op_cloud.delete_flavor('vanilla')
@mock.patch.object(shade.OpenStackCloud, '_compute_client') @mock.patch.object(shade.OpenStackCloud, '_compute_client')
@mock.patch.object(shade.OpenStackCloud, 'nova_client') @mock.patch.object(shade.OpenStackCloud, 'nova_client')