def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) if self.NAME not in props: props[self.NAME] = self.physical_resource_name() props['vip_subnet_id'] = props.pop(self.VIP_SUBNET) return props
def test_template_as_resource(self): """ Test that the resulting resource has the right prop and attrib schema. Note that this test requires the Wordpress_Single_Instance.yaml template in the templates directory since we want to test using a non-trivial template. """ test_templ_name = "WordPress_Single_Instance.yaml" path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates', test_templ_name) # check if its in the directory list vs. exists to work around # case-insensitive file systems self.assertIn(test_templ_name, os.listdir(os.path.dirname(path))) with open(path) as test_templ_file: test_templ = test_templ_file.read() self.assertTrue(test_templ, "Empty test template") self.m.StubOutWithMock(urlfetch, "get") urlfetch.get(test_templ_name, allowed_schemes=('file', )).AndRaise( urlfetch.URLFetchError(_('Failed to retrieve template'))) urlfetch.get(test_templ_name, allowed_schemes=('http', 'https')).AndReturn(test_templ) parsed_test_templ = template_format.parse(test_templ) self.m.ReplayAll() stack = parser.Stack(utils.dummy_context(), 'test_stack', template.Template(empty_template), stack_id=str(uuid.uuid4())) properties = { "KeyName": "mykeyname", "DBName": "wordpress1", "DBUsername": "******", "DBPassword": "******", "DBRootPassword": "******", "LinuxDistribution": "U10" } definition = rsrc_defn.ResourceDefinition("test_templ_resource", test_templ_name, properties) templ_resource = resource.Resource("test_templ_resource", definition, stack) self.m.VerifyAll() self.assertIsInstance(templ_resource, template_resource.TemplateResource) for prop in parsed_test_templ.get("Parameters", {}): self.assertIn(prop, templ_resource.properties) for attrib in parsed_test_templ.get("Outputs", {}): self.assertIn(attrib, templ_resource.attributes) for k, v in properties.items(): self.assertEqual(v, templ_resource.properties[k]) self.assertEqual( { 'WordPress_Single_Instance.yaml': 'WordPress_Single_Instance.yaml', 'resources': {} }, stack.env.user_env_as_dict()["resource_registry"]) self.assertNotIn('WordPress_Single_Instance.yaml', resources.global_env().registry._registry)
def test_template_as_resource(self): """ Test that the resulting resource has the right prop and attrib schema. Note that this test requires the Wordpress_Single_Instance.yaml template in the templates directory since we want to test using a non-trivial template. """ test_templ_name = "WordPress_Single_Instance.yaml" path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'templates', test_templ_name) # check if its in the directory list vs. exists to work around # case-insensitive file systems self.assertIn(test_templ_name, os.listdir(os.path.dirname(path))) with open(path) as test_templ_file: test_templ = test_templ_file.read() self.assertTrue(test_templ, "Empty test template") self.m.StubOutWithMock(urlfetch, "get") urlfetch.get(test_templ_name, allowed_schemes=('file',) ).AndRaise(urlfetch.URLFetchError( _('Failed to retrieve template'))) urlfetch.get(test_templ_name, allowed_schemes=('http', 'https')).AndReturn(test_templ) parsed_test_templ = template_format.parse(test_templ) self.m.ReplayAll() stack = parser.Stack(utils.dummy_context(), 'test_stack', template.Template(empty_template), stack_id=str(uuid.uuid4())) properties = { "KeyName": "mykeyname", "DBName": "wordpress1", "DBUsername": "******", "DBPassword": "******", "DBRootPassword": "******", "LinuxDistribution": "U10" } definition = rsrc_defn.ResourceDefinition("test_templ_resource", test_templ_name, properties) templ_resource = resource.Resource("test_templ_resource", definition, stack) self.m.VerifyAll() self.assertIsInstance(templ_resource, template_resource.TemplateResource) for prop in parsed_test_templ.get("Parameters", {}): self.assertIn(prop, templ_resource.properties) for attrib in parsed_test_templ.get("Outputs", {}): self.assertIn(attrib, templ_resource.attributes) for k, v in properties.items(): self.assertEqual(v, templ_resource.properties[k]) self.assertEqual( {'WordPress_Single_Instance.yaml': 'WordPress_Single_Instance.yaml', 'resources': {}}, stack.env.user_env_as_dict()["resource_registry"]) self.assertNotIn('WordPress_Single_Instance.yaml', resources.global_env().registry._registry)
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) if self.NAME not in props: props[self.NAME] = self.physical_resource_name() props['listener_id'] = props.pop(self.LISTENER) if self.REDIRECT_POOL in props: props['redirect_pool_id'] = props.pop(self.REDIRECT_POOL) return props
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) if self.NAME not in props: props[self.NAME] = self.physical_resource_name() props['vip_subnet_id'] = props.pop(self.VIP_SUBNET) if 'tenant_id' in props: props['project_id'] = props.pop('tenant_id') return props
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) if self.NAME not in props: props[self.NAME] = self.physical_resource_name() if self.LOADBALANCER in props: props['loadbalancer_id'] = props.pop(self.LOADBALANCER) if self.DEFAULT_POOL in props: props['default_pool_id'] = props.pop(self.DEFAULT_POOL) return props
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) if self.NAME not in props: props[self.NAME] = self.physical_resource_name() if self.LISTENER in props: props['listener_id'] = props.pop(self.LISTENER) if self.LOADBALANCER in props: props['loadbalancer_id'] = props.pop(self.LOADBALANCER) session_p = props.get(self.SESSION_PERSISTENCE) if session_p is not None: session_props = dict( (k, v) for k, v in session_p.items() if v is not None) props[self.SESSION_PERSISTENCE] = session_props return props
def prepare_properties(self, properties, name): props = dict((k, v) for k, v in properties.items() if v is not None and k != self.SERVICE_LIST) if 'name' in properties.keys(): props.setdefault('name', name) if self.SERVICE_LIST in properties.keys(): services = properties.get(self.SERVICE_LIST) if len(services) > 0: prop = dict() prop['nuage_services'] = ",".join(str(i) for i in services) props.update(prop) return props
def cfn_to_ceilometer(self, stack, properties): kwargs = actions_to_urls(stack, properties) if kwargs.get(self.METER_NAME) in NOVA_METERS: prefix = 'user_metadata.' else: prefix = 'metering.' for k, v in iter(properties.items()): if k == self.MATCHING_METADATA: # make sure we have matching_metadata that looks like this: # matching_metadata: {metadata.$prefix.x} kwargs[k] = {} for m_k, m_v in six.iteritems(v): if m_k.startswith('metadata.%s' % prefix): kwargs[k][m_k] = m_v elif m_k.startswith(prefix): kwargs[k]['metadata.%s' % m_k] = m_v else: kwargs[k]['metadata.%s%s' % (prefix, m_k)] = m_v return kwargs
def actions_to_urls(stack, properties): kwargs = {} for k, v in iter(properties.items()): if k in [ALARM_ACTIONS, OK_ACTIONS, INSUFFICIENT_DATA_ACTIONS] and v is not None: kwargs[k] = [] for act in v: # if the action is a resource name # we ask the destination resource for an alarm url. # the template writer should really do this in the # template if possible with: # {Fn::GetAtt: ['MyAction', 'AlarmUrl']} if act in stack: url = stack[act].FnGetAtt('AlarmUrl') kwargs[k].append(url) else: kwargs[k].append(act) else: kwargs[k] = v return kwargs
def actions_to_urls(stack, properties): kwargs = {} for k, v in iter(properties.items()): if k in [ALARM_ACTIONS, OK_ACTIONS, INSUFFICIENT_DATA_ACTIONS ] and v is not None: kwargs[k] = [] for act in v: # if the action is a resource name # we ask the destination resource for an alarm url. # the template writer should really do this in the # template if possible with: # {Fn::GetAtt: ['MyAction', 'AlarmUrl']} if act in stack: url = stack[act].FnGetAtt('AlarmUrl') kwargs[k].append(url) else: kwargs[k].append(act) else: kwargs[k] = v return kwargs
def actions_to_urls(self, stack, properties): kwargs = {} for k, v in iter(properties.items()): if k in ['alarm_actions', 'ok_actions', 'undetermined_actions' ] and v is not None: kwargs[k] = [] for act in v: # if the action is a resource name # we ask the destination resource for an alarm url. # the template writer should really do this in the # template if possible with: # {Fn::GetAtt: ['MyAction', 'AlarmUrl']} if act in stack: url = stack[act].FnGetAtt('AlarmUrl') kwargs[k].append(url) else: if act: kwargs[k].append(act) else: kwargs[k] = v return kwargs
def actions_to_urls(self, stack, properties): kwargs = {} for k, v in iter(properties.items()): if k in ['alarm_actions', 'ok_actions', 'undetermined_actions'] and v is not None: kwargs[k] = [] for act in v: # if the action is a resource name # we ask the destination resource for an alarm url. # the template writer should really do this in the # template if possible with: # {Fn::GetAtt: ['MyAction', 'AlarmUrl']} if act in stack: url = stack[act].FnGetAtt('AlarmUrl') kwargs[k].append(url) else: if act: kwargs[k].append(act) else: kwargs[k] = v return kwargs
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) props.pop(self.L7POLICY) return props
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) if self.POOL in props: props['pool_id'] = props.pop(self.POOL) return props
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) if self.NAME not in props: props[self.NAME] = self.physical_resource_name() return props
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) props.pop(self.POOL) if self.SUBNET in props: props['subnet_id'] = props.pop(self.SUBNET) return props
def _prepare_args(self, properties): props = dict((k, v) for k, v in properties.items() if v is not None) if self.NAME not in props: props[self.NAME] = self.physical_resource_name() props['flavor_profile_id'] = props.pop(self.FLAVOR_PROFILE) return props