From 6882530a788f084dd7d09cce657512c35e86833e Mon Sep 17 00:00:00 2001 From: Chris Donati Date: Thu, 21 Apr 2016 16:58:51 -0700 Subject: [PATCH 1/2] Ensure length of disk name does not exceed GCE max --- lib/agents/gce_agent.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/agents/gce_agent.py b/lib/agents/gce_agent.py index 114f90bc..d28b4a00 100644 --- a/lib/agents/gce_agent.py +++ b/lib/agents/gce_agent.py @@ -687,8 +687,8 @@ def generate_disk_name(self, parameters): Returns: A str, a disk name associated with the root disk of AppScale on GCE. """ - return "appscale{0}{1}".format(parameters[self.PARAM_GROUP], - str(int(time.time() * 1000))) + return '{group}-{time}'.format(group=parameters[self.PARAM_GROUP], + time=int(time.time() * 1000))[:60] def create_scratch_disk(self, parameters): """ Creates a disk from a given machine image. From 582f71629d365b0d332ec38e05fb6fbf72acf07a Mon Sep 17 00:00:00 2001 From: Chris Donati Date: Thu, 21 Apr 2016 16:59:08 -0700 Subject: [PATCH 2/2] Reduce length of instance name --- lib/agents/gce_agent.py | 4 ++-- test/test_appscale_terminate_instances.py | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/agents/gce_agent.py b/lib/agents/gce_agent.py index d28b4a00..14b3bc75 100644 --- a/lib/agents/gce_agent.py +++ b/lib/agents/gce_agent.py @@ -657,7 +657,7 @@ def describe_instances(self, parameters, pending=False): auth_http = credentials.authorize(http) request = gce_service.instances().list( project=parameters[self.PARAM_PROJECT], - filter="name eq appscale-{0}-.*".format(parameters[self.PARAM_GROUP]), + filter="name eq {group}-.*".format(group=parameters[self.PARAM_GROUP]), zone=parameters[self.PARAM_ZONE] ) response = request.execute(http=auth_http) @@ -773,7 +773,7 @@ def run_instances(self, count, parameters, security_configured): instances = { # Truncate the name down to the first 62 characters, since GCE doesn't # let us use arbitrarily long instance names. - 'name': "appscale-{0}-{1}".format(group, uuid.uuid4())[:62], + 'name': '{group}-{uuid}'.format(group=group, uuid=uuid.uuid4())[:62], 'machineType': machine_type_url, 'disks':[{ 'source': disk_url, diff --git a/test/test_appscale_terminate_instances.py b/test/test_appscale_terminate_instances.py index 78b45240..fa4e93ae 100644 --- a/test/test_appscale_terminate_instances.py +++ b/test/test_appscale_terminate_instances.py @@ -400,7 +400,7 @@ def test_terminate_in_gce_and_succeeds(self): u'status': u'RUNNING', u'kind': u'compute#instance', u'machineType': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/global/machineTypes/n1-standard-1', - u'name': u'appscale-bazboogroup-one', + u'name': u'bazboogroup-one', u'zone': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b', u'tags': {u'fingerprint': u'42WmSpB8rSM='}, u'image': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/global/images/lucid64', @@ -421,7 +421,7 @@ def test_terminate_in_gce_and_succeeds(self): }, u'creationTimestamp': u'2013-05-22T11:52:33.254-07:00', u'id': u'8684033495853907982', - u'selfLink': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b/instances/appscale-bazboogroup-feb10b11-62bc-4536-ac25-9734f2267d6d', + u'selfLink': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b/instances/bazboogroup-feb10b11-62bc-4536-ac25-9734f2267d6d', u'networkInterfaces': [{ u'accessConfigs': [{ u'kind': u'compute#accessConfig', @@ -439,7 +439,7 @@ def test_terminate_in_gce_and_succeeds(self): u'status': u'RUNNING', u'kind': u'compute#instance', u'machineType': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/global/machineTypes/n1-standard-1', - u'name': u'appscale-bazboogroup-two', + u'name': u'bazboogroup-two', u'zone': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b', u'tags': {u'fingerprint': u'42WmSpB8rSM='}, u'image': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/global/images/lucid64', @@ -460,7 +460,7 @@ def test_terminate_in_gce_and_succeeds(self): }, u'creationTimestamp': u'2013-05-22T11:52:33.254-07:00', u'id': u'8684033495853907982', - u'selfLink': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b/instances/appscale-bazboogroup-feb10b11-62bc-4536-ac25-9734f2267d6d', + u'selfLink': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b/instances/bazboogroup-feb10b11-62bc-4536-ac25-9734f2267d6d', u'networkInterfaces': [{ u'accessConfigs': [{ u'kind': u'compute#accessConfig', @@ -487,7 +487,7 @@ def test_terminate_in_gce_and_succeeds(self): fake_instances = flexmock(name='fake_instances') fake_instances.should_receive('list').with_args(project=project_id, - filter="name eq appscale-bazboogroup-.*", zone=zone) \ + filter="name eq bazboogroup-.*", zone=zone) \ .and_return(fake_list_instance_request) fake_gce.should_receive('instances').and_return(fake_instances) @@ -501,7 +501,7 @@ def test_terminate_in_gce_and_succeeds(self): u'startTime': u'2013-05-27T10:44:51.849-07:00', u'insertTime': u'2013-05-27T10:44:51.806-07:00', u'targetId': u'12912855597472179535', - u'targetLink': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b/instances/appscale-appscalecgb20-0cf89267-5887-4048-b774-ca20de47a07f', + u'targetLink': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b/instances/appscalecgb20-0cf89267-5887-4048-b774-ca20de47a07f', u'operationType': u'delete', u'progress': 0, u'id': u'11114355109942058217', @@ -517,7 +517,7 @@ def test_terminate_in_gce_and_succeeds(self): u'startTime': u'2013-05-27T10:44:51.849-07:00', u'insertTime': u'2013-05-27T10:44:51.806-07:00', u'targetId': u'12912855597472179535', - u'targetLink': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b/instances/appscale-appscalecgb20-0cf89267-5887-4048-b774-ca20de47a07f', + u'targetLink': u'https://www.googleapis.com/compute/v1beta14/projects/appscale.com:appscale/zones/my-zone-1b/instances/appscalecgb20-0cf89267-5887-4048-b774-ca20de47a07f', u'operationType': u'delete', u'progress': 0, u'id': u'11114355109942058217', @@ -529,14 +529,14 @@ def test_terminate_in_gce_and_succeeds(self): fake_delete_instance_request_one.should_receive('execute').with_args( http=fake_authorized_http).and_return(delete_instance_info_one) fake_instances.should_receive('delete').with_args(project=project_id, - zone=zone, instance='appscale-bazboogroup-one').and_return( + zone=zone, instance='bazboogroup-one').and_return( fake_delete_instance_request_one) fake_delete_instance_request_two = flexmock(name='fake_delete_instance_request_two') fake_delete_instance_request_two.should_receive('execute').with_args( http=fake_authorized_http).and_return(delete_instance_info_two) fake_instances.should_receive('delete').with_args(project=project_id, - zone=zone, instance='appscale-bazboogroup-two').and_return( + zone=zone, instance='bazboogroup-two').and_return( fake_delete_instance_request_two) # mock out our waiting for the instances to be deleted