from heat.common import template_format from heat.engine import properties from heat.engine import resource from heat.engine import scheduler from heat.engine.resources.quantum import net from heat.engine.resources.quantum import subnet from heat.engine.resources.quantum import floatingip from heat.engine.resources.quantum import port from heat.engine.resources.quantum import router from heat.engine.resources.quantum.quantum import QuantumResource as qr from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests.utils import setup_dummy_db from heat.tests.utils import parse_stack quantumclient = try_import('quantumclient.v2_0.client') qe = try_import('quantumclient.common.exceptions') quantum_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Template to test Quantum resources", "Parameters" : {}, "Resources" : { "network": { "Type": "OS::Quantum::Net", "Properties": { "name": "the_network" } }, "unnamed_network": {
import xmlrpclib except ImportError: # NOTE(jaypipes): xmlrpclib was renamed to xmlrpc.client in Python3 # however the function and object call signatures # remained the same. This whole try/except block should # be removed and replaced with a call to six.moves once # six 1.4.2 is released. See http://bit.ly/1bqrVzu import xmlrpc.client as xmlrpclib import six from heat.openstack.common import gettextutils from heat.openstack.common import importutils from heat.openstack.common import timeutils netaddr = importutils.try_import("netaddr") _nasty_type_tests = [inspect.ismodule, inspect.isclass, inspect.ismethod, inspect.isfunction, inspect.isgeneratorfunction, inspect.isgenerator, inspect.istraceback, inspect.isframe, inspect.iscode, inspect.isbuiltin, inspect.isroutine, inspect.isabstract] _simple_types = (six.string_types + six.integer_types + (type(None), bool, float)) def to_primitive(value, convert_instances=False, convert_datetime=True, level=0, max_depth=3): """Convert a complex object into primitives.
import types import uuid import eventlet import greenlet from oslo.config import cfg import six from six import moves from heat.openstack.common import excutils from heat.openstack.common.gettextutils import _ # noqa from heat.openstack.common import importutils from heat.openstack.common import jsonutils from heat.openstack.common.rpc import common as rpc_common zmq = importutils.try_import('eventlet.green.zmq') # for convenience, are not modified. pformat = pprint.pformat Timeout = eventlet.timeout.Timeout LOG = rpc_common.LOG RemoteError = rpc_common.RemoteError RPCException = rpc_common.RPCException zmq_opts = [ cfg.StrOpt('rpc_zmq_bind_address', default='*', help='ZeroMQ bind address. Should be a wildcard (*), ' 'an ethernet interface, or IP. ' 'The "host" option should point or resolve to this ' 'address.'),
import mox from mox import IgnoreArg from testtools import skipIf from heat.common import exception from heat.common import template_format from heat.engine import clients from heat.engine.resources.neutron import network_gateway from heat.engine.resources.neutron import neutron_utils from heat.engine import scheduler from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import fakes from heat.tests import utils neutronclient = try_import('neutronclient.v2_0.client') neutronV20 = try_import('neutronclient.neutron.v2_0') qe = try_import('neutronclient.common.exceptions') gw_template_deprecated = ''' { 'AWSTemplateFormatVersion': '2010-09-09', 'Description': 'Template to test Network Gateway resource', 'Parameters': {}, 'Resources': { 'NetworkGateway': { 'Type': 'OS::Neutron::NetworkGateway', 'Properties': { 'name': 'NetworkGateway', 'devices': [{
from heat.common import exception from heat.common import template_format from heat.engine import clients from heat.engine import parser from heat.engine.properties import schemata from heat.engine import resource from heat.engine.resources.ceilometer import alarm from heat.engine import rsrc_defn from heat.engine import scheduler from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import generic_resource from heat.tests import utils ceilometerclient = try_import('ceilometerclient.v2') alarm_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Alarm Test", "Parameters" : {}, "Resources" : { "MEMAlarmHigh": { "Type": "OS::Ceilometer::Alarm", "Properties": { "description": "Scale-up if MEM > 50% for 1 minute", "meter_name": "MemoryUtilization", "statistic": "avg", "period": "60", "evaluation_periods": "1",
from heat.common import exception from heat.common import template_format from heat.engine import properties from heat.engine import scheduler from heat.engine.resources.quantum import net from heat.engine.resources.quantum import subnet from heat.engine.resources.quantum import floatingip from heat.engine.resources.quantum import port from heat.engine.resources.quantum.quantum import QuantumResource as qr from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests.utils import setup_dummy_db from heat.tests.utils import parse_stack quantumclient = try_import('quantumclient.v2_0.client') quantum_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Template to test Quantum resources", "Parameters" : {}, "Resources" : { "network": { "Type": "OS::Quantum::Net", "Properties": { "name": "the_network" } }, "unnamed_network": { "Type": "OS::Quantum::Net"
from heat.common import template_format from heat.db import api as db_api from heat.engine import clients from heat.engine import environment from heat.engine import parser from heat.engine.resources import image from heat.engine.resources import instance from heat.engine.resources import nova_utils from heat.engine import template from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import fakes from heat.tests import utils from heat.tests.v1_1 import fakes as v1fakes neutroncli = try_import('neutronclient') as_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "AutoScaling Test", "Parameters" : { "ImageId": {"Type": "String"}, "KeyName": {"Type": "String"}, "SubnetId": {"Type": "String"} }, "Resources" : { "SvrGrp" : { "Type" : "AWS::AutoScaling::AutoScalingGroup", "Properties" : { "AvailabilityZones" : ["nova"],
from testtools import skipIf from heat.common import exception from heat.common import template_format from heat.engine import clients from heat.engine.resources.neutron import loadbalancer from heat.engine.resources.neutron import neutron_utils from heat.engine import scheduler from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import fakes from heat.tests import utils from heat.tests.v1_1 import fakes as nova_fakes neutronclient = try_import('neutronclient.v2_0.client') health_monitor_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Template to test load balancer resources", "Parameters" : {}, "Resources" : { "monitor": { "Type": "OS::Neutron::HealthMonitor", "Properties": { "type": "HTTP", "delay": 3, "max_retries": 5, "timeout": 10 }
import types import uuid import eventlet import greenlet from oslo.config import cfg import six from six import moves from heat.openstack.common import excutils from heat.openstack.common.gettextutils import _, _LE, _LI from heat.openstack.common import importutils from heat.openstack.common import jsonutils from heat.openstack.common.rpc import common as rpc_common zmq = importutils.try_import('eventlet.green.zmq') # for convenience, are not modified. pformat = pprint.pformat Timeout = eventlet.timeout.Timeout LOG = rpc_common.LOG RemoteError = rpc_common.RemoteError RPCException = rpc_common.RPCException zmq_opts = [ cfg.StrOpt('rpc_zmq_bind_address', default='*', help='ZeroMQ bind address. Should be a wildcard (*), ' 'an ethernet interface, or IP. ' 'The "host" option should point or resolve to this ' 'address.'),
import time import eventlet import greenlet from oslo.config import cfg import six from heat.openstack.common import excutils from heat.openstack.common.gettextutils import _, _LE, _LI from heat.openstack.common import importutils from heat.openstack.common import jsonutils from heat.openstack.common import log as logging from heat.openstack.common.rpc import amqp as rpc_amqp from heat.openstack.common.rpc import common as rpc_common qpid_codec = importutils.try_import("qpid.codec010") qpid_messaging = importutils.try_import("qpid.messaging") qpid_exceptions = importutils.try_import("qpid.messaging.exceptions") LOG = logging.getLogger(__name__) qpid_opts = [ cfg.StrOpt('qpid_hostname', default='localhost', help='Qpid broker hostname'), cfg.IntOpt('qpid_port', default=5672, help='Qpid broker port'), cfg.ListOpt('qpid_hosts', default=['$qpid_hostname:$qpid_port'], help='Qpid HA cluster host:port pairs'), cfg.StrOpt('qpid_username', default='',
class validateTest(HeatTestCase): def setUp(self): super(validateTest, self).setUp() resources.initialise() self.fc = fakes.FakeClient() resources.initialise() utils.setup_dummy_db() self.ctx = utils.dummy_context() def test_validate_volumeattach_valid(self): t = template_format.parse(test_template_volumeattach % 'vdq') stack = parser.Stack(self.ctx, 'test_stack', parser.Template(t)) volumeattach = stack['MountPoint'] self.assertIsNone(volumeattach.validate()) def test_validate_volumeattach_invalid(self): t = template_format.parse(test_template_volumeattach % 'sda') stack = parser.Stack(self.ctx, 'test_stack', parser.Template(t)) volumeattach = stack['MountPoint'] self.assertRaises(exception.StackValidationFailed, volumeattach.validate) def test_validate_ref_valid(self): t = template_format.parse(test_template_ref % 'WikiDatabase') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual('test.', res['Description']) def test_validate_hot_valid(self): t = template_format.parse(""" heat_template_version: 2013-05-23 description: test. resources: my_instance: type: AWS::EC2::Instance """) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual('test.', res['Description']) def test_validate_ref_invalid(self): t = template_format.parse(test_template_ref % 'WikiDatabasez') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertNotEqual(res['Description'], 'Successfully validated') def test_validate_findinmap_valid(self): t = template_format.parse(test_template_findinmap_valid) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual('test.', res['Description']) def test_validate_findinmap_invalid(self): t = template_format.parse(test_template_findinmap_invalid) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertNotEqual(res['Description'], 'Successfully validated') def test_validate_parameters(self): t = template_format.parse(test_template_ref % 'WikiDatabase') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) # Note: the assertion below does not expect a CFN dict of the parameter # but a dict of the parameters.Schema object. # For API CFN backward compatibility, formating to CFN is done in the # API layer in heat.engine.api.format_validate_parameter. expected = { 'KeyName': { 'Type': 'String', 'Description': 'Name of an existing EC2KeyPair to enable SSH ' 'access to the instances', 'NoEcho': 'false', 'Label': 'KeyName' } } self.assertEqual(expected, res['Parameters']) def test_validate_hot_parameter_label(self): t = template_format.parse(test_template_hot_parameter_label) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) parameters = res['Parameters'] expected = { 'KeyName': { 'Type': 'String', 'Description': 'Name of an existing key pair to use for the ' 'instance', 'NoEcho': 'false', 'Label': 'Nova KeyPair Name' } } self.assertEqual(expected, parameters) def test_validate_hot_no_parameter_label(self): t = template_format.parse(test_template_hot_no_parameter_label) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) parameters = res['Parameters'] expected = { 'KeyName': { 'Type': 'String', 'Description': 'Name of an existing key pair to use for the ' 'instance', 'NoEcho': 'false', 'Label': 'KeyName' } } self.assertEqual(expected, parameters) def test_validate_cfn_parameter_label(self): t = template_format.parse(test_template_cfn_parameter_label) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) parameters = res['Parameters'] expected = { 'KeyName': { 'Type': 'String', 'Description': 'Name of an existing EC2KeyPair to enable SSH ' 'access to the instances', 'NoEcho': 'false', 'Label': 'Nova KeyPair Name' } } self.assertEqual(expected, parameters) def test_validate_properties(self): t = template_format.parse(test_template_invalid_property) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual({'Error': 'Unknown Property UnknownProperty'}, res) def test_invalid_resources(self): t = template_format.parse(test_template_invalid_resources) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual( { 'Error': 'Resources must contain Resource. ' 'Found a [string] instead' }, res) def test_unimplemented_property(self): t = template_format.parse(test_template_unimplemented_property) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual( {'Error': 'Property SourceDestCheck not implemented yet'}, res) def test_invalid_deletion_policy(self): t = template_format.parse(test_template_invalid_deletion_policy) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual({'Error': 'Invalid DeletionPolicy Destroy'}, res) def test_snapshot_deletion_policy(self): t = template_format.parse(test_template_snapshot_deletion_policy) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual({'Error': 'Snapshot DeletionPolicy not supported'}, res) @skipIf( try_import('cinderclient.v1.volume_backups') is None, 'unable to import volume_backups') def test_volume_snapshot_deletion_policy(self): t = template_format.parse(test_template_volume_snapshot) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(service.EngineListener, 'start') service.EngineListener.start().AndReturn(None) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual({'Description': u'test.', 'Parameters': {}}, res) def test_unregistered_key(self): t = template_format.parse(test_unregistered_key) template = parser.Template(t) params = {'KeyName': 'not_registered'} stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment(params)) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.StubOutWithMock(clients.OpenStackClients, 'nova') clients.OpenStackClients.nova().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.StackValidationFailed, resource.validate) def test_unregistered_image(self): t = template_format.parse(test_template_image) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment({'KeyName': 'test'})) self.m.StubOutWithMock(clients.OpenStackClients, 'nova') clients.OpenStackClients.nova().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.StackValidationFailed, resource.validate) self.m.VerifyAll() def test_duplicated_image(self): t = template_format.parse(test_template_image) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment({'KeyName': 'test'})) image_type = collections.namedtuple("Image", ("id", "name")) image_list = [ image_type(id='768b5464-3df5-4abf-be33-63b60f8b99d0', name='image_name'), image_type(id='a57384f5-690f-48e1-bf46-c4291e6c887e', name='image_name') ] self.m.StubOutWithMock(self.fc.images, 'list') self.fc.images.list().AndReturn(image_list) self.m.StubOutWithMock(clients.OpenStackClients, 'nova') clients.OpenStackClients.nova().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.StackValidationFailed, resource.validate) self.m.VerifyAll() def test_invalid_security_groups_with_nics(self): t = template_format.parse(test_template_invalid_secgroups) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment({'KeyName': 'test'})) image_type = collections.namedtuple("Image", ("id", "name")) image_list = [ image_type(id='768b5464-3df5-4abf-be33-63b60f8b99d0', name='image_name') ] self.m.StubOutWithMock(self.fc.images, 'list') self.fc.images.list().AndReturn(image_list) self.m.StubOutWithMock(clients.OpenStackClients, 'nova') clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.ResourcePropertyConflict, resource.validate) def test_invalid_security_group_ids_with_nics(self): t = template_format.parse(test_template_invalid_secgroupids) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment({'KeyName': 'test'})) image_type = collections.namedtuple("Image", ("id", "name")) image_list = [ image_type(id='768b5464-3df5-4abf-be33-63b60f8b99d0', name='image_name') ] self.m.StubOutWithMock(self.fc.images, 'list') self.fc.images.list().AndReturn(image_list) self.m.StubOutWithMock(clients.OpenStackClients, 'nova') clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.ResourcePropertyConflict, resource.validate) def test_client_exception_from_nova_client(self): t = template_format.parse(test_template_nova_client_exception) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template) self.m.StubOutWithMock(self.fc.images, 'list') self.fc.images.list().AndRaise( clients.novaclient.exceptions.ClientException(500)) self.m.StubOutWithMock(clients.OpenStackClients, 'nova') clients.OpenStackClients.nova().MultipleTimes().AndReturn(self.fc) self.m.ReplayAll() self.assertRaises(exception.StackValidationFailed, stack.validate) self.m.VerifyAll() def test_validate_unique_logical_name(self): t = template_format.parse(test_template_unique_logical_name) template = parser.Template(t) stack = parser.Stack( self.ctx, 'test_stack', template, environment.Environment({ 'AName': 'test', 'KeyName': 'test' })) self.assertRaises(exception.StackValidationFailed, stack.validate) def test_validate_duplicate_parameters_in_group(self): t = template_format.parse(test_template_duplicate_parameters) template = HOTemplate(t) stack = parser.Stack( self.ctx, 'test_stack', template, environment.Environment({ 'KeyName': 'test', 'ImageId': 'sometestid', 'db_password': '******' })) exc = self.assertRaises(exception.StackValidationFailed, stack.validate) self.assertEqual( _('The InstanceType parameter must be assigned to ' 'one Parameter Group only.'), str(exc)) def test_validate_invalid_parameter_in_group(self): t = template_format.parse(test_template_invalid_parameter_name) template = HOTemplate(t) stack = parser.Stack( self.ctx, 'test_stack', template, environment.Environment({ 'KeyName': 'test', 'ImageId': 'sometestid', 'db_password': '******' })) exc = self.assertRaises(exception.StackValidationFailed, stack.validate) self.assertEqual( _('The Parameter name (SomethingNotHere) does not ' 'reference an existing parameter.'), str(exc)) def test_validate_no_parameters_in_group(self): t = template_format.parse(test_template_no_parameters) template = HOTemplate(t) stack = parser.Stack(self.ctx, 'test_stack', template) exc = self.assertRaises(exception.StackValidationFailed, stack.validate) self.assertEqual( _('Parameters must be provided for each Parameter ' 'Group.'), str(exc))
from heat.common import exception from heat.common import template_format from heat.engine import clients from heat.engine import parser from heat.engine.properties import schemata from heat.engine import resource from heat.engine.resources.ceilometer import alarm from heat.engine import scheduler from heat.engine import stack_user from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import fakes from heat.tests import generic_resource from heat.tests import utils ceilometerclient = try_import('ceilometerclient.v2') alarm_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Alarm Test", "Parameters" : {}, "Resources" : { "MEMAlarmHigh": { "Type": "OS::Ceilometer::Alarm", "Properties": { "description": "Scale-up if MEM > 50% for 1 minute", "meter_name": "MemoryUtilization", "statistic": "avg", "period": "60", "evaluation_periods": "1",
from testtools import skipIf from heat.common import template_format from heat.engine import clients from heat.engine import resource from heat.engine.resources.neutron import neutron_utils from heat.engine import scheduler from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import fakes from heat.tests import utils from ..resources import extraroute # noqa neutronclient = try_import('neutronclient.v2_0.client') qe = try_import('neutronclient.common.exceptions') neutron_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Template to test OS::Neutron::ExtraRoute resources", "Parameters" : {}, "Resources" : { "router": { "Type": "OS::Neutron::Router" }, "extraroute1": { "Type": "OS::Neutron::ExtraRoute", "Properties": { "router_id": { "Ref" : "router" },
except ImportError: # Python 2.6 UnsupportedOperation = None import eventlet from eventlet import event from oslo.config import cfg from heat.openstack.common import eventlet_backdoor from heat.openstack.common.gettextutils import _LE, _LI, _LW from heat.openstack.common import importutils from heat.openstack.common import log as logging from heat.openstack.common import systemd from heat.openstack.common import threadgroup rpc = importutils.try_import('heat.openstack.common.rpc') CONF = cfg.CONF LOG = logging.getLogger(__name__) def _sighup_supported(): return hasattr(signal, 'SIGHUP') def _is_daemon(): # The process group for a foreground process will match the # process group of the controlling terminal. If those values do # not match, or ioctl() fails on the stdout file handle, we assume # the process is running in the background as a daemon. # http://www.gnu.org/software/bash/manual/bashref.html#Job-Control-Basics try:
# License for the specific language governing permissions and limitations # under the License. from testtools import skipIf from heat.common import exception from heat.common import template_format from heat.engine import clients from heat.engine.resources.neutron import metering from heat.engine import scheduler from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import fakes from heat.tests import utils neutronclient = try_import('neutronclient.v2_0.client') metering_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Template to test metering resources", "Parameters" : {}, "Resources" : { "label": { "Type": "OS::Neutron::MeteringLabel", "Properties": { "name": "TestLabel", "description": "Description of TestLabel" } }, "rule": {
from heat.common import exception from heat.common import template_format from heat.engine import scheduler from heat.engine.resources import volume as vol from heat.engine import clients from heat.engine import resource from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests.v1_1 import fakes from heat.tests.utils import setup_dummy_db from heat.tests.utils import parse_stack from cinderclient.v1 import client as cinderclient volume_backups = try_import('cinderclient.v1.volume_backups') volume_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Volume Test", "Parameters" : {}, "Resources" : { "WikiDatabase": { "Type": "AWS::EC2::Instance", "Properties": { "ImageId" : "foo", "InstanceType" : "m1.large", "KeyName" : "test", "UserData" : "some data" }
# under the License. from testtools import skipIf from heat.common import exception from heat.common import template_format from heat.engine import clients from heat.engine.resources import s3 from heat.engine import scheduler from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import fakes from heat.tests import utils swiftclient = try_import('swiftclient.client') swift_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Template to test S3 Bucket resources", "Resources" : { "S3BucketWebsite" : { "Type" : "AWS::S3::Bucket", "DeletionPolicy" : "Delete", "Properties" : { "AccessControl" : "PublicRead", "WebsiteConfiguration" : { "IndexDocument" : "index.html", "ErrorDocument" : "error.html" }
# under the License. from testtools import skipIf from heat.common import exception from heat.common import template_format from heat.openstack.common.importutils import try_import from heat.engine.resources import s3 from heat.engine import resource from heat.engine import clients from heat.engine import scheduler from heat.tests.common import HeatTestCase from heat.tests import utils from heat.tests import fakes swiftclient = try_import('swiftclient.client') swift_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Template to test S3 Bucket resources", "Resources" : { "S3BucketWebsite" : { "Type" : "AWS::S3::Bucket", "DeletionPolicy" : "Delete", "Properties" : { "AccessControl" : "PublicRead", "WebsiteConfiguration" : { "IndexDocument" : "index.html", "ErrorDocument" : "error.html" }
from heat.common import exception from heat.common import template_format from heat.engine import clients from heat.engine import resource from heat.engine.resources import image from heat.engine.resources import instance from heat.engine.resources import nova_utils from heat.engine.resources import volume as vol from heat.engine import scheduler from heat.openstack.common.importutils import try_import from heat.tests.common import HeatTestCase from heat.tests import utils from heat.tests.v1_1 import fakes volume_backups = try_import('cinderclient.v1.volume_backups') volume_template = ''' { "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "Volume Test", "Parameters" : {}, "Resources" : { "WikiDatabase": { "Type": "AWS::EC2::Instance", "Properties": { "ImageId" : "foo", "InstanceType" : "m1.large", "KeyName" : "test", "UserData" : "some data" }
class validateTest(HeatTestCase): def setUp(self): super(validateTest, self).setUp() resources.initialise() self.fc = fakes.FakeClient() resources.initialise() utils.setup_dummy_db() self.ctx = utils.dummy_context() def test_validate_volumeattach_valid(self): t = template_format.parse(test_template_volumeattach % 'vdq') stack = parser.Stack(self.ctx, 'test_stack', parser.Template(t)) volumeattach = stack['MountPoint'] self.assertTrue(volumeattach.validate() is None) def test_validate_volumeattach_invalid(self): t = template_format.parse(test_template_volumeattach % 'sda') stack = parser.Stack(self.ctx, 'test_stack', parser.Template(t)) volumeattach = stack['MountPoint'] self.assertRaises(exception.StackValidationFailed, volumeattach.validate) def test_validate_ref_valid(self): t = template_format.parse(test_template_ref % 'WikiDatabase') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res['Description'], 'test.') def test_validate_hot_valid(self): t = template_format.parse(""" heat_template_version: 2013-05-23 description: test. resources: my_instance: type: AWS::EC2::Instance """) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res['Description'], 'test.') def test_validate_ref_invalid(self): t = template_format.parse(test_template_ref % 'WikiDatabasez') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertNotEqual(res['Description'], 'Successfully validated') def test_validate_findinmap_valid(self): t = template_format.parse(test_template_findinmap_valid) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res['Description'], 'test.') def test_validate_findinmap_invalid(self): t = template_format.parse(test_template_findinmap_invalid) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertNotEqual(res['Description'], 'Successfully validated') def test_validate_parameters(self): t = template_format.parse(test_template_ref % 'WikiDatabase') self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual( res['Parameters'], { 'KeyName': { 'Type': 'String', 'Description': 'Name of an existing EC2KeyPair to enable SSH ' 'access to the instances' } }) def test_validate_properties(self): t = template_format.parse(test_template_invalid_property) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res, {'Error': 'Unknown Property UnknownProperty'}) def test_invalid_resources(self): t = template_format.parse(test_template_invalid_resources) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual( { 'Error': 'Resources must contain Resource. ' 'Found a [string] instead' }, res) def test_unimplemented_property(self): t = template_format.parse(test_template_unimplemented_property) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual( res, {'Error': 'Property SourceDestCheck not implemented yet'}) def test_invalid_deletion_policy(self): t = template_format.parse(test_template_invalid_deletion_policy) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res, {'Error': 'Invalid DeletionPolicy Destroy'}) def test_snapshot_deletion_policy(self): t = template_format.parse(test_template_snapshot_deletion_policy) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res, {'Error': 'Snapshot DeletionPolicy not supported'}) @skipIf( try_import('cinderclient.v1.volume_backups') is None, 'unable to import volume_backups') def test_volume_snapshot_deletion_policy(self): t = template_format.parse(test_template_volume_snapshot) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() engine = service.EngineService('a', 't') res = dict(engine.validate_template(None, t)) self.assertEqual(res, {'Description': u'test.', 'Parameters': {}}) def test_unregistered_key(self): t = template_format.parse(test_unregistered_key) template = parser.Template(t) params = {'KeyName': 'not_registered'} stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment(params)) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.UserKeyPairMissing, resource.validate) def test_unregistered_image(self): t = template_format.parse(test_template_image) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment({'KeyName': 'test'})) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.ImageNotFound, resource.validate) self.m.VerifyAll() def test_duplicated_image(self): t = template_format.parse(test_template_image) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment({'KeyName': 'test'})) class image_type(object): def __init__(self, id, name): self.id = id self.name = name image_list = [ image_type(id='768b5464-3df5-4abf-be33-63b60f8b99d0', name='image_name'), image_type(id='a57384f5-690f-48e1-bf46-c4291e6c887e', name='image_name') ] self.m.StubOutWithMock(self.fc.images, 'list') self.fc.images.list().AndReturn(image_list) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.NoUniqueImageFound, resource.validate) self.m.VerifyAll() def test_invalid_security_groups_with_nics(self): t = template_format.parse(test_template_invalid_secgroups) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment({'KeyName': 'test'})) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.ResourcePropertyConflict, resource.validate) def test_invalid_security_group_ids_with_nics(self): t = template_format.parse(test_template_invalid_secgroupids) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template, environment.Environment({'KeyName': 'test'})) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() resource = stack['Instance'] self.assertRaises(exception.ResourcePropertyConflict, resource.validate) def test_client_exception_from_nova_client(self): t = template_format.parse(test_template_nova_client_exception) template = parser.Template(t) stack = parser.Stack(self.ctx, 'test_stack', template) self.m.StubOutWithMock(self.fc.images, 'list') self.fc.images.list()\ .AndRaise(clients.novaclient.exceptions.ClientException(500)) self.m.StubOutWithMock(instances.Instance, 'nova') instances.Instance.nova().AndReturn(self.fc) self.m.ReplayAll() self.assertRaises(exception.Error, stack.validate) self.m.VerifyAll() def test_validate_unique_logical_name(self): t = template_format.parse(test_template_unique_logical_name) template = parser.Template(t) stack = parser.Stack( self.ctx, 'test_stack', template, environment.Environment({ 'AName': 'test', 'KeyName': 'test' })) self.assertRaises(exception.StackValidationFailed, stack.validate)