summaryrefslogtreecommitdiff
path: root/heat/tests
diff options
context:
space:
mode:
Diffstat (limited to 'heat/tests')
-rw-r--r--heat/tests/aws/test_user.py5
-rw-r--r--heat/tests/clients/test_neutron_client.py27
-rw-r--r--heat/tests/common.py8
-rw-r--r--heat/tests/db/test_sqlalchemy_api.py12
-rw-r--r--heat/tests/openstack/heat/test_software_deployment.py9
-rw-r--r--heat/tests/openstack/neutron/test_neutron_firewall.py43
-rw-r--r--heat/tests/openstack/neutron/test_neutron_loadbalancer.py1
-rw-r--r--heat/tests/openstack/neutron/test_neutron_port.py17
-rw-r--r--heat/tests/openstack/nova/test_host_aggregate.py46
9 files changed, 138 insertions, 30 deletions
diff --git a/heat/tests/aws/test_user.py b/heat/tests/aws/test_user.py
index ba4424d32..fdb7ebc07 100644
--- a/heat/tests/aws/test_user.py
+++ b/heat/tests/aws/test_user.py
@@ -379,8 +379,9 @@ class AccessKeyTest(common.HeatTestCase):
# working via retrieving the keypair from keystone
resource_data_object.ResourceData.delete(rsrc, 'credential_id')
resource_data_object.ResourceData.delete(rsrc, 'secret_key')
- rs_data = resource_data_object.ResourceData.get_all(rsrc)
- self.assertEqual(0, len(list(six.iterkeys(rs_data))))
+ self.assertRaises(exception.NotFound,
+ resource_data_object.ResourceData.get_all,
+ rsrc)
rsrc._secret = None
self.assertEqual(self.fc.secret,
diff --git a/heat/tests/clients/test_neutron_client.py b/heat/tests/clients/test_neutron_client.py
index 5bf033ea3..aafb64590 100644
--- a/heat/tests/clients/test_neutron_client.py
+++ b/heat/tests/clients/test_neutron_client.py
@@ -241,6 +241,33 @@ class NeutronConstraintsValidate(common.HeatTestCase):
cmd_resource=self.cmd_resource)])
+class NeutronProviderConstraintsValidate(common.HeatTestCase):
+ scenarios = [
+ ('validate_lbaasv1',
+ dict(constraint_class=nc.LBaasV1ProviderConstraint,
+ service_type='LOADBALANCER')),
+ ('validate_lbaasv2',
+ dict(constraint_class=lc.LBaasV2ProviderConstraint,
+ service_type='LOADBALANCERV2'))
+ ]
+
+ def test_provider_validate(self):
+ nc = mock.Mock()
+ mock_create = self.patchobject(neutron.NeutronClientPlugin, '_create')
+ mock_create.return_value = nc
+ providers = {
+ 'service_providers': [
+ {'service_type': 'LOADBANALCERV2', 'name': 'haproxy'},
+ {'service_type': 'LOADBANALCER', 'name': 'haproxy'}
+ ]
+ }
+ nc.list_service_providers.return_value = providers
+ constraint = self.constraint_class()
+ ctx = utils.dummy_context()
+ self.assertTrue(constraint.validate('haproxy', ctx))
+ self.assertFalse(constraint.validate("bar", ctx))
+
+
class NeutronClientPluginExtensionsTests(NeutronClientPluginTestCase):
"""Tests for extensions in neutronclient."""
diff --git a/heat/tests/common.py b/heat/tests/common.py
index af2bfbc71..6889e2368 100644
--- a/heat/tests/common.py
+++ b/heat/tests/common.py
@@ -277,6 +277,10 @@ class HeatTestCase(testscenarios.WithScenarios,
validate = self.patchobject(neutron.RouterConstraint, 'validate')
validate.return_value = True
+ def stub_QoSPolicyConstraint_validate(self):
+ validate = self.patchobject(neutron.QoSPolicyConstraint, 'validate')
+ validate.return_value = True
+
def stub_NovaNetworkConstraint(self):
validate = self.patchobject(nova.NetworkConstraint, 'validate')
validate.return_value = True
@@ -289,3 +293,7 @@ class HeatTestCase(testscenarios.WithScenarios,
def stub_SaharaPluginConstraint(self):
validate = self.patchobject(sahara.PluginConstraint, 'validate')
validate.return_value = True
+
+ def stub_ProviderConstraint_validate(self):
+ validate = self.patchobject(neutron.ProviderConstraint, 'validate')
+ validate.return_value = True
diff --git a/heat/tests/db/test_sqlalchemy_api.py b/heat/tests/db/test_sqlalchemy_api.py
index b2bbd051e..643d68864 100644
--- a/heat/tests/db/test_sqlalchemy_api.py
+++ b/heat/tests/db/test_sqlalchemy_api.py
@@ -1914,7 +1914,8 @@ class DBAPIStackTest(common.HeatTestCase):
ctx, stacks[s].id)
for r in stacks[s].resources:
self.assertRaises(exception.NotFound,
- db_api.resource_data_get_all(r))
+ db_api.resource_data_get_all(r.context,
+ r.id))
self.assertEqual([],
db_api.event_get_all_by_stack(ctx,
stacks[s].id))
@@ -2183,13 +2184,14 @@ class DBAPIResourceDataTest(common.HeatTestCase):
self.assertEqual('test_value', val)
# get all by querying for data
- vals = db_api.resource_data_get_all(self.resource)
+ vals = db_api.resource_data_get_all(self.resource.context,
+ self.resource.id)
self.assertEqual(2, len(vals))
self.assertEqual('foo', vals.get('test_resource_key'))
self.assertEqual('test_value', vals.get('encryped_resource_key'))
# get all by using associated resource data
- vals = db_api.resource_data_get_all(None, self.resource.data)
+ vals = db_api.resource_data_get_all(None, None, self.resource.data)
self.assertEqual(2, len(vals))
self.assertEqual('foo', vals.get('test_resource_key'))
self.assertEqual('test_value', vals.get('encryped_resource_key'))
@@ -2206,6 +2208,10 @@ class DBAPIResourceDataTest(common.HeatTestCase):
self.ctx, self.resource.id, 'test_resource_key')
self.assertIsNotNone(res_data)
+ self.assertRaises(exception.NotFound, db_api.resource_data_get_all,
+ self.resource.context,
+ self.resource.id)
+
class DBAPIEventTest(common.HeatTestCase):
def setUp(self):
diff --git a/heat/tests/openstack/heat/test_software_deployment.py b/heat/tests/openstack/heat/test_software_deployment.py
index 999f75dd4..79ad669a5 100644
--- a/heat/tests/openstack/heat/test_software_deployment.py
+++ b/heat/tests/openstack/heat/test_software_deployment.py
@@ -715,7 +715,10 @@ class SoftwareDeploymentTest(common.HeatTestCase):
self.rpc_client.show_software_deployment.return_value = sd
self.deployment.resource_id = sd['id']
config_id = '0ff2e903-78d7-4cca-829e-233af3dae705'
- prop_diff = {'config': config_id}
+ prop_diff = {
+ 'config': config_id,
+ 'name': 'new_name'
+ }
props = copy.copy(rsrc.properties.data)
props.update(prop_diff)
snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props)
@@ -730,6 +733,10 @@ class SoftwareDeploymentTest(common.HeatTestCase):
(self.ctx, sd['id']),
self.rpc_client.show_software_deployment.call_args[0])
+ self.assertEqual(
+ 'new_name',
+ self.rpc_client.create_software_config.call_args[1]['name'])
+
self.assertEqual({
'deployment_id': 'c8a19429-7fde-47ea-a42f-40045488226c',
'action': 'UPDATE',
diff --git a/heat/tests/openstack/neutron/test_neutron_firewall.py b/heat/tests/openstack/neutron/test_neutron_firewall.py
index 917ceef15..45e8c780c 100644
--- a/heat/tests/openstack/neutron/test_neutron_firewall.py
+++ b/heat/tests/openstack/neutron/test_neutron_firewall.py
@@ -21,6 +21,7 @@ from heat.common import exception
from heat.common import template_format
from heat.engine.clients.os import neutron
from heat.engine.resources.openstack.neutron import firewall
+from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests import common
from heat.tests import utils
@@ -85,15 +86,23 @@ class FirewallTest(common.HeatTestCase):
self.patchobject(neutron.NeutronClientPlugin, 'has_extension',
return_value=True)
- def create_firewall(self):
- neutronclient.Client.create_firewall({
- 'firewall': {
- 'name': 'test-firewall', 'admin_state_up': True,
- 'router_ids': ['router_1', 'router_2'],
- 'firewall_policy_id': 'policy-id', 'shared': True}}
- ).AndReturn({'firewall': {'id': '5678'}})
-
+ def create_firewall(self, value_specs=True):
snippet = template_format.parse(firewall_template)
+ if not value_specs:
+ del snippet['resources']['firewall']['properties']['value_specs']
+ neutronclient.Client.create_firewall({
+ 'firewall': {
+ 'name': 'test-firewall', 'admin_state_up': True,
+ 'firewall_policy_id': 'policy-id', 'shared': True}}
+ ).AndReturn({'firewall': {'id': '5678'}})
+ else:
+ neutronclient.Client.create_firewall({
+ 'firewall': {
+ 'name': 'test-firewall', 'admin_state_up': True,
+ 'router_ids': ['router_1', 'router_2'],
+ 'firewall_policy_id': 'policy-id', 'shared': True}}
+ ).AndReturn({'firewall': {'id': '5678'}})
+
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
return firewall.Firewall(
@@ -207,6 +216,24 @@ class FirewallTest(common.HeatTestCase):
self.m.VerifyAll()
+ def test_update_with_value_specs(self):
+ rsrc = self.create_firewall(value_specs=False)
+ neutronclient.Client.update_firewall(
+ '5678', {'firewall': {'router_ids': ['router_1',
+ 'router_2']}})
+ self.m.ReplayAll()
+ scheduler.TaskRunner(rsrc.create)()
+ prop_diff = {
+ 'value_specs': {
+ 'router_ids': ['router_1', 'router_2']
+ }
+ }
+ update_snippet = rsrc_defn.ResourceDefinition(rsrc.name,
+ rsrc.type(),
+ prop_diff)
+ rsrc.handle_update(update_snippet, {}, prop_diff)
+ self.m.VerifyAll()
+
class FirewallPolicyTest(common.HeatTestCase):
diff --git a/heat/tests/openstack/neutron/test_neutron_loadbalancer.py b/heat/tests/openstack/neutron/test_neutron_loadbalancer.py
index 6e255555d..c84327dad 100644
--- a/heat/tests/openstack/neutron/test_neutron_loadbalancer.py
+++ b/heat/tests/openstack/neutron/test_neutron_loadbalancer.py
@@ -600,6 +600,7 @@ class PoolTest(common.HeatTestCase):
neutronclient.Client.show_vip('xyz').AndReturn(
{'vip': {'status': 'ACTIVE'}})
snippet = template_format.parse(pool_template_with_provider)
+ self.stub_ProviderConstraint_validate()
self.stack = utils.parse_stack(snippet)
resource_defns = self.stack.t.resource_definitions(self.stack)
rsrc = loadbalancer.Pool(
diff --git a/heat/tests/openstack/neutron/test_neutron_port.py b/heat/tests/openstack/neutron/test_neutron_port.py
index 51f96ae78..c03011403 100644
--- a/heat/tests/openstack/neutron/test_neutron_port.py
+++ b/heat/tests/openstack/neutron/test_neutron_port.py
@@ -21,6 +21,7 @@ from oslo_serialization import jsonutils
from heat.common import exception
from heat.common import template_format
+from heat.engine.clients.os import neutron
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests import common
@@ -398,7 +399,8 @@ class NeutronPortTest(common.HeatTestCase):
],
'name': utils.PhysName('test_stack', 'port'),
'admin_state_up': True,
- 'device_owner': u'network:dhcp'}
+ 'device_owner': u'network:dhcp'
+ }
self._mock_create_with_security_groups(port_prop)
@@ -416,18 +418,25 @@ class NeutronPortTest(common.HeatTestCase):
'name': utils.PhysName('test_stack', 'port'),
'admin_state_up': True,
'device_owner': u'network:dhcp'}
+ policy_id = '8a2f582a-e1cd-480f-b85d-b02631c10656'
new_props = props.copy()
new_props['name'] = "new_name"
new_props['security_groups'] = [
'8a2f582a-e1cd-480f-b85d-b02631c10656']
+ new_props['device_id'] = 'fc68ea2c-b60b-4b4f-bd82-94ec81110766'
+ new_props['device_owner'] = 'network:router_interface'
new_props_update = new_props.copy()
new_props_update.pop('network_id')
+ new_props_update['qos_policy_id'] = policy_id
+ new_props['qos_policy'] = policy_id
new_props1 = new_props.copy()
new_props1.pop('security_groups')
+ new_props1['qos_policy'] = None
new_props_update1 = new_props_update.copy()
new_props_update1['security_groups'] = [
'0389f747-7785-4757-b7bb-2ab07e4b09c3']
+ new_props_update1['qos_policy_id'] = None
neutronV20.find_resourceid_by_name_or_id(
mox.IsA(neutronclient.Client),
@@ -452,6 +461,10 @@ class NeutronPortTest(common.HeatTestCase):
"ip_address": "10.0.0.2"
}
}})
+
+ self.patchobject(neutron.NeutronClientPlugin, 'get_qos_policy_id')
+ neutron.NeutronClientPlugin.get_qos_policy_id.return_value = policy_id
+ self.stub_QoSPolicyConstraint_validate()
neutronclient.Client.update_port(
'fc68ea2c-b60b-4b4f-bd82-94ec81110766',
{'port': new_props_update}
@@ -490,7 +503,9 @@ class NeutronPortTest(common.HeatTestCase):
update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
new_props)
scheduler.TaskRunner(port.update, update_snippet)()
+
# update again to test port without security group
+ # and without qos_policy
update_snippet = rsrc_defn.ResourceDefinition(port.name, port.type(),
new_props1)
scheduler.TaskRunner(port.update, update_snippet)()
diff --git a/heat/tests/openstack/nova/test_host_aggregate.py b/heat/tests/openstack/nova/test_host_aggregate.py
index 80ccc137e..3dc6b9433 100644
--- a/heat/tests/openstack/nova/test_host_aggregate.py
+++ b/heat/tests/openstack/nova/test_host_aggregate.py
@@ -80,36 +80,52 @@ class NovaHostAggregateTest(common.HeatTestCase):
value = mock.MagicMock()
self.aggregates.get.return_value = value
prop_diff = {'name': 'new_host_aggregate',
- "availability_zone": "new_nova"}
+ 'metadata': {'availability_zone': 'new_nova'},
+ 'availability_zone': 'new_nova'}
expected = {'name': 'new_host_aggregate',
- "availability_zone": "new_nova"}
+ 'availability_zone': 'new_nova'}
self.my_aggregate.handle_update(
json_snippet=None, tmpl_diff=None, prop_diff=prop_diff
)
value.update.assert_called_once_with(expected)
def test_aggregate_handle_update_hosts(self):
- value = mock.MagicMock()
- self.aggregates.get.return_value = value
+ ag = mock.MagicMock()
+ ag.hosts = ['host_1', 'host_2']
+ self.aggregates.get.return_value = ag
prop_diff = {'hosts': ['host_1', 'host_3']}
add_host_expected = 'host_3'
remove_host_expected = 'host_2'
self.my_aggregate.handle_update(
json_snippet=None, tmpl_diff=None, prop_diff=prop_diff
)
- self.assertEqual(0, value.update.call_count)
- self.assertEqual(0, value.set_metadata.call_count)
- value.add_host.assert_called_once_with(add_host_expected)
- value.remove_host.assert_called_once_with(remove_host_expected)
+ self.assertEqual(0, ag.update.call_count)
+ self.assertEqual(0, ag.set_metadata.call_count)
+ ag.add_host.assert_called_once_with(add_host_expected)
+ ag.remove_host.assert_called_once_with(remove_host_expected)
def test_aggregate_handle_update_metadata(self):
- value = mock.MagicMock()
- self.aggregates.get.return_value = value
- prop_diff = {'metadata': {"availability_zone": "nova3"}}
- set_metadata_expected = {"availability_zone": "nova3"}
+ ag = mock.MagicMock()
+ self.aggregates.get.return_value = ag
+ prop_diff = {'metadata': {'availability_zone': 'nova3'}}
+ set_metadata_expected = {'availability_zone': 'nova3'}
self.my_aggregate.handle_update(
json_snippet=None, tmpl_diff=None, prop_diff=prop_diff
)
- self.assertEqual(0, value.update.call_count)
- self.assertEqual(0, value.add_host.call_count)
- value.set_metadata.assert_called_once_with(set_metadata_expected)
+ self.assertEqual(0, ag.update.call_count)
+ self.assertEqual(0, ag.add_host.call_count)
+ self.assertEqual(0, ag.remove_host.call_count)
+ ag.set_metadata.assert_called_once_with(set_metadata_expected)
+
+ def test_aggregate_handle_delete(self):
+ ag = mock.MagicMock()
+ ag.id = '927202df-1afb-497f-8368-9c2d2f26e5db'
+ ag.hosts = ['host_1']
+ self.aggregates.get.return_value = ag
+ self.aggregates.hosts = ag.hosts
+ self.my_aggregate.resource_id = ag.id
+ self.my_aggregate.handle_delete()
+ self.assertEqual(1, self.aggregates.get.call_count)
+ self.assertEqual(ag.hosts, self.aggregates.hosts)
+ ag.remove_host.assert_called_once_with(ag.hosts[0])
+ self.aggregates.delete.assert_called_once_with(ag.id)