def test_lb_reload_members(self): t = template_format.parse(as_template) t['Resources']['ElasticLoadBalancer'] = { 'Type': 'OS::Neutron::LoadBalancer', 'Properties': { 'protocol_port': 8080, 'pool_id': 'pool123' } } expected = { 'Type': 'OS::Neutron::LoadBalancer', 'Properties': { 'protocol_port': 8080, 'pool_id': 'pool123', 'members': [u'aaaabbbbcccc'] } } self.m.StubOutWithMock(short_id, 'generate_id') short_id.generate_id().MultipleTimes().AndReturn('aaaabbbbcccc') self.m.StubOutWithMock(neutron_lb.LoadBalancer, 'handle_update') neutron_lb.LoadBalancer.handle_update(expected, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None) now = timeutils.utcnow() self._stub_meta_expected(now, 'ExactCapacity : 1') self._stub_create(1) self.m.ReplayAll() stack = utils.parse_stack(t, params=self.params) self.create_scaling_group(t, stack, 'WebServerGroup') self.m.VerifyAll()
def test_lb_reload_members(self): t = template_format.parse(as_template) t['Resources']['ElasticLoadBalancer'] = { 'Type': 'OS::Neutron::LoadBalancer', 'Properties': { 'protocol_port': 8080, 'pool_id': 'pool123' } } expected = { 'Type': 'OS::Neutron::LoadBalancer', 'Properties': { 'protocol_port': 8080, 'pool_id': 'pool123', 'members': [u'aaaabbbbcccc']} } self.m.StubOutWithMock(short_id, 'generate_id') short_id.generate_id().AndReturn('aaaabbbbcccc') self.m.StubOutWithMock(neutron_lb.LoadBalancer, 'handle_update') neutron_lb.LoadBalancer.handle_update(expected, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None) now = timeutils.utcnow() self._stub_meta_expected(now, 'ExactCapacity : 1') self._stub_create(1) self.m.ReplayAll() stack = utils.parse_stack(t, params=self.params) self.create_scaling_group(t, stack, 'WebServerGroup') self.m.VerifyAll()
def handle_create(self): LOG.debug(_("G_cloud server create")) properties = dict() for key, value in self.properties.items(): if key == self.USER_DATA: if self.properties[self.USER_DATA] and self.properties[self.USER_DATA_FORMAT] == self.RAW: properties['userdata'] = self.properties[self.USER_DATA] else: properties[key] = self.properties[key] properties.pop(self.USER_DATA_FORMAT) properties.update({"alias": short_id.generate_id()}) properties.update({"netcardName": short_id.generate_id()}) if self.properties[self.STACKID] == "owner": properties.update({"appId": self.stack.id}) else: properties.update({"appId": self.properties[self.STACKID]}) #if self.properties[self.CREATE_USER_ID] != "owner": # properties.update({"createUserId": self.properties[self.CREATE_USER_ID]}) #properties.update({"appType": self.stack.stack_apps_style}) #properties.update({"appName": self.stack.app_name}) properties[self.NETWORK] = self.properties[self.SUBNET] properties.pop(self.SUBNET) server = self.client.create(properties) if server['success']: self.inst_id = server['data'][0]['instanceId'] self.resource_id_set(self.inst_id) return server
def test_lb_reload_static_resolve(self): t = template_format.parse(as_template) properties = t['Resources']['ElasticLoadBalancer']['Properties'] properties['AvailabilityZones'] = {'Fn::GetAZs': ''} self.m.StubOutWithMock(parser.Stack, 'get_availability_zones') parser.Stack.get_availability_zones().MultipleTimes().AndReturn( ['abc', 'xyz']) # Check that the Fn::GetAZs is correctly resolved expected = { u'Type': u'AWS::ElasticLoadBalancing::LoadBalancer', u'Properties': { 'Instances': ['aaaabbbbcccc'], u'Listeners': [{ u'InstancePort': u'80', u'LoadBalancerPort': u'80', u'Protocol': u'HTTP' }], u'AvailabilityZones': ['abc', 'xyz'] } } self.m.StubOutWithMock(short_id, 'generate_id') short_id.generate_id().MultipleTimes().AndReturn('aaaabbbbcccc') now = timeutils.utcnow() self._stub_meta_expected(now, 'ExactCapacity : 1') self._stub_create(1) self.m.ReplayAll() stack = utils.parse_stack(t, params=self.params) lb = stack['ElasticLoadBalancer'] self.m.StubOutWithMock(lb, 'handle_update') lb.handle_update(expected, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None) self.m.ReplayAll() rsrc = self.create_scaling_group(t, stack, 'WebServerGroup') self.assertEqual(utils.PhysName(stack.name, rsrc.name), rsrc.FnGetRefId()) self.assertEqual(1, len(grouputils.get_member_names(rsrc))) props = copy.copy(rsrc.properties.data) props['Cooldown'] = '61' update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) scheduler.TaskRunner(rsrc.update, update_snippet)() rsrc.delete() self.m.VerifyAll()
def test_generate_ids(self): allowed_chars = "abcdefghijklmnopqrstuvwxyz234567" ids = [short_id.generate_id() for i in range(25)] for id in ids: self.assertEqual(12, len(id)) self.assertEqual(id, id.translate(allowed_chars)) self.assertEqual(1, ids.count(id))
def test_generate_ids(self): allowed_chars = [ord(c) for c in u'abcdefghijklmnopqrstuvwxyz234567'] ids = [short_id.generate_id() for i in range(25)] for id in ids: self.assertEqual(12, len(id)) self.assertFalse(id.translate({c: None for c in allowed_chars})) self.assertEqual(1, ids.count(id))
def test_generate_ids(self): allowed_chars = 'abcdefghijklmnopqrstuvwxyz234567' ids = [short_id.generate_id() for i in range(25)] for id in ids: self.assertEqual(len(id), 12) self.assertFalse(id.translate(None, allowed_chars)) self.assertEqual(ids.count(id), 1)
def test_lb_reload_static_resolve(self): t = template_format.parse(as_template) properties = t['Resources']['ElasticLoadBalancer']['Properties'] properties['AvailabilityZones'] = {'Fn::GetAZs': ''} self.m.StubOutWithMock(parser.Stack, 'get_availability_zones') parser.Stack.get_availability_zones().MultipleTimes().AndReturn( ['abc', 'xyz']) # Check that the Fn::GetAZs is correctly resolved expected = {u'Type': u'AWS::ElasticLoadBalancing::LoadBalancer', u'Properties': {'Instances': ['aaaabbbbcccc'], u'Listeners': [{u'InstancePort': u'80', u'LoadBalancerPort': u'80', u'Protocol': u'HTTP'}], u'AvailabilityZones': ['abc', 'xyz']}} self.m.StubOutWithMock(short_id, 'generate_id') short_id.generate_id().AndReturn('aaaabbbbcccc') now = timeutils.utcnow() self._stub_meta_expected(now, 'ExactCapacity : 1') self._stub_create(1) self.m.ReplayAll() stack = utils.parse_stack(t, params=self.params) lb = stack['ElasticLoadBalancer'] self.m.StubOutWithMock(lb, 'handle_update') lb.handle_update(expected, mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(None) self.m.ReplayAll() rsrc = self.create_scaling_group(t, stack, 'WebServerGroup') self.assertEqual(utils.PhysName(stack.name, rsrc.name), rsrc.FnGetRefId()) self.assertEqual(1, len(rsrc.get_instance_names())) props = copy.copy(rsrc.properties.data) props['Cooldown'] = '61' update_snippet = rsrc_defn.ResourceDefinition(rsrc.name, rsrc.type(), props) scheduler.TaskRunner(rsrc.update, update_snippet)() rsrc.delete() self.m.VerifyAll()
def instance_templates(num_replace): for i in range(num_instances): if i < len(instances): inst = instances[i] if inst.t != instance_definition and num_replace > 0: num_replace -= 1 yield inst.name, instance_definition else: yield inst.name, inst.t else: yield short_id.generate_id(), instance_definition
def _create_porperties(self): if self.properties[self.POOL_NAME] == "auto": properties = { 'size': self.properties[self.SIZE], "volume_type": self._format_properpy(self.properties[self.VOLUME_TYPE]), } else: properties = { 'size': self.properties[self.SIZE], 'pool_name': self.properties[self.POOL_NAME], "volume_type": self._format_properpy(self.properties[self.VOLUME_TYPE]), } if self.properties[self.VOLUME_TYPE] == "Local": properties['host_id'] = self.properties[self.HOST_NAME] properties['name'] = short_id.generate_id() properties['createmethod'] = "create" properties['count'] = 1 return properties
def resource_templates(old_resources, resource_definition, num_resources, num_replace): """ Create the template for the nested stack of existing and new instances For rolling update, if launch configuration is different, the instance definition should come from the existing instance instead of using the new launch configuration. """ old_resources = old_resources[-num_resources:] num_create = num_resources - len(old_resources) num_replace -= num_create for i in range(num_resources): if i < len(old_resources): old_name, old_template = old_resources[i] if old_template != resource_definition and num_replace > 0: num_replace -= 1 yield old_name, resource_definition else: yield old_name, old_template else: yield short_id.generate_id(), resource_definition
def _create_container_name(self, name=None): return name or '%s-%s-%s' % (self.stack.name, self.name, short_id.generate_id())
def _create_container_name(self): return '%s-%s-%s' % (self.stack.name, self.name, short_id.generate_id())
def _create_container_name(self, name=None): return name or "%s-%s-%s" % (self.stack.name, self.name, short_id.generate_id())
def parse_stack(self, templ_obj): stack_name = 'test_value_stack_%s' % short_id.generate_id() stack = parser.Stack(utils.dummy_context(), stack_name, templ_obj) stack.validate() stack.store() return stack