Skip to content

Commit

Permalink
Merge pull request #503 from cdonati/gce-disk-length
Browse files Browse the repository at this point in the history
Reduce GCE resource length
  • Loading branch information
menivaitsi committed Apr 22, 2016
2 parents 9b23e7f + 582f716 commit b361f84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions lib/agents/gce_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions test/test_appscale_terminate_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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)

Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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
Expand Down

0 comments on commit b361f84

Please sign in to comment.