Skip to content

Commit 5480445

Browse files
authored
Pull request update/250410
0d95aa2 OSN-XX. Fix test 03a644f OSN-773. Update email templates to include organization ID in links f2d5ba2 OSN-695. Fix 500 on updating schedule for task if schedule deleted d2defdd OSN-758. Use regions map to get regions names for AWS instead of hardcoded
2 parents 1a37409 + 0d95aa2 commit 5480445

File tree

13 files changed

+121
-112
lines changed

13 files changed

+121
-112
lines changed

bumiworker/bumiworker/modules/recommendations/instance_migration.py

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -46,44 +46,6 @@
4646
'us': ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2'],
4747
}
4848
AWS_SKU_INDEX = 'AwsSkuIndex'
49-
# this map is necessary to map human-readable names from SKU attributes to
50-
# region codes. I added method in cloud adapter to get this map, but it requires
51-
# permission ssm:GetParameter, so it may not work on most accounts. That's why
52-
# I saved it here
53-
AWS_REGION_NAMES_TO_CODES = {
54-
'Africa (Cape Town)': 'af-south-1',
55-
'Asia Pacific (Hong Kong)': 'ap-east-1',
56-
'Asia Pacific (Tokyo)': 'ap-northeast-1',
57-
'Asia Pacific (Seoul)': 'ap-northeast-2',
58-
'Asia Pacific (Osaka)': 'ap-northeast-3',
59-
'Asia Pacific (Mumbai)': 'ap-south-1',
60-
'Asia Pacific (Hyderabad)': 'ap-south-2',
61-
'Asia Pacific (Singapore)': 'ap-southeast-1',
62-
'Asia Pacific (Sydney)': 'ap-southeast-2',
63-
'Asia Pacific (Jakarta)': 'ap-southeast-3',
64-
'Asia Pacific (Melbourne)': 'ap-southeast-4',
65-
'Asia Pacific (Malaysia)': 'ap-southeast-5',
66-
'Asia Pacific (Thailand)': 'ap-southeast-7',
67-
'Canada (Central)': 'ca-central-1',
68-
'Canada West (Calgary)': 'ca-west-1',
69-
'Europe (Frankfurt)': 'eu-central-1',
70-
'Europe (Zurich)': 'eu-central-2',
71-
'Europe (Stockholm)': 'eu-north-1',
72-
'Europe (Milan)': 'eu-south-1',
73-
'Europe (Spain)': 'eu-south-2',
74-
'Europe (Ireland)': 'eu-west-1',
75-
'Europe (London)': 'eu-west-2',
76-
'Europe (Paris)': 'eu-west-3',
77-
'Israel (Tel Aviv)': 'il-central-1',
78-
'Middle East (Bahrain)': 'me-south-1',
79-
'Middle East (UAE)': 'me-central-1',
80-
'Mexico (Central)': 'mx-central-1',
81-
'South America (Sao Paulo)': 'sa-east-1',
82-
'US East (N. Virginia)': 'us-east-1',
83-
'US East (Ohio)': 'us-east-2',
84-
'US West (N. California)': 'us-west-1',
85-
'US West (Oregon)': 'us-west-2',
86-
}
8749
unique_sku_fields = [
8850
'location',
8951
'locationType',
@@ -171,6 +133,11 @@ def get_skus_from_cloud(sku):
171133
def get_aws_recommendations(self, instance_map, cloud_account_map,
172134
excluded_pools):
173135
result = []
136+
coordinates = self.aws.get_regions_coordinates()
137+
aws_region_names_to_codes = {}
138+
for region_id, coord in coordinates.items():
139+
if 'name' in coord:
140+
aws_region_names_to_codes[coord['name']] = region_id
174141
res = self.mongo_client.restapi.raw_expenses.aggregate([
175142
{'$match': {
176143
'$and': [
@@ -205,9 +172,9 @@ def get_aws_recommendations(self, instance_map, cloud_account_map,
205172
for sku_dict in similar_skus:
206173
_index = sku_dict['location'].index('(')
207174
location_detailed = sku_dict['location'][_index:]
208-
for test_region in AWS_REGION_NAMES_TO_CODES:
175+
for test_region in aws_region_names_to_codes:
209176
if location_detailed in test_region:
210-
region = AWS_REGION_NAMES_TO_CODES.get(test_region)
177+
region = aws_region_names_to_codes.get(test_region)
211178
break
212179
else:
213180
continue

docker_images/herald_executor/worker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ def _snake_to_camel_case(filter_name):
500500
filter_name = parts[0] + ''.join(x.title() for x in parts[1:])
501501
return filter_name
502502

503-
def _get_org_constraint_link(self, constraint, created_at, filters):
503+
def _get_org_constraint_link(self, constraint, created_at, filters, organization):
504504
link_filters = defaultdict(list)
505505
for f, v in filters.items():
506506
f = self._snake_to_camel_case(f)
@@ -555,7 +555,7 @@ def _get_org_constraint_link(self, constraint, created_at, filters):
555555
if link_filters.get('recommendations'):
556556
link_filters['availableSavings'] = link_filters['recommendations']
557557
link_filters.pop('recommendations')
558-
query = self.rest_cl.query_url(**link_filters)
558+
query = self.rest_cl.query_url(organizationId=organization['id'], **link_filters)
559559
link = 'https://{0}/resources'.format(self.config_cl.public_ip())
560560
link += query
561561
return link
@@ -631,7 +631,7 @@ def execute_organization_constraint_violated(self, constraint_id,
631631
for constraint_type in CONSTRAINT_TYPES:
632632
constraint_data[constraint_type] = constraint_type == constraint['type']
633633
link = self._get_org_constraint_link(
634-
constraint, latest_hit['created_at'], c_filters)
634+
constraint, latest_hit['created_at'], c_filters, organization)
635635
if constraint['type'] in ['expiring_budget', 'tagging_policy']:
636636
constraint_data['definition']['start_date'] = utcfromtimestamp(
637637
int(constraint_data['definition']['start_date'])).strftime(

herald/modules/email_generator/templates/anomaly_detection_alert.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@
284284
<tr>
285285
<td class="pad">
286286
<div class="alignment" align="center">
287-
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://{{etcd.control_panel_link}}/anomalies/{{texts.organization_constraint.id}}" style="height:42px;width:149px;v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#f58535"><w:anchorlock/><v:textbox inset="0px,0px,0px,0px"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]-->
288-
<a href="https://{{ etcd.control_panel_link }}/anomalies/{{ texts.organization_constraint.id }}"
287+
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://{{etcd.control_panel_link}}/anomalies/{{texts.organization_constraint.id}}?organizationId={{texts.organization.id}}" style="height:42px;width:149px;v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#f58535"><w:anchorlock/><v:textbox inset="0px,0px,0px,0px"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]-->
288+
<a href="https://{{ etcd.control_panel_link }}/anomalies/{{ texts.organization_constraint.id }}?organizationId={{texts.organization.id}}"
289289
target="_blank" rel="noopener"
290290
style="text-decoration:none;display:inline-block;color:#ffffff;background-color:#f58535;border-radius:4px;width:auto;border-top:0px solid #F58535;font-weight:400;border-right:0px solid #F58535;border-bottom:0px solid #F58535;border-left:0px solid #F58535;padding-top:5px;padding-bottom:5px;font-family:Arial, Helvetica Neue, Helvetica, sans-serif;text-align:center;mso-border-alt:none;word-break:keep-all;"><span
291291
style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;letter-spacing:normal;"><span

herald/modules/email_generator/templates/organization_policy_expiring_budget.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@
195195
<tr>
196196
<td class="pad">
197197
<div class="alignment" align="center">
198-
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}" style="height:42px;width:149px;v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#f58535"><w:anchorlock/><v:textbox inset="0px,0px,0px,0px"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]--><a href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}" target="_blank" rel="noopener" style="text-decoration:none;display:inline-block;color:#ffffff;background-color:#f58535;border-radius:4px;width:auto;border-top:0px solid #F58535;font-weight:400;border-right:0px solid #F58535;border-bottom:0px solid #F58535;border-left:0px solid #F58535;padding-top:5px;padding-bottom:5px;font-family:Arial, Helvetica Neue, Helvetica, sans-serif;text-align:center;mso-border-alt:none;word-break:keep-all;"><span style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;letter-spacing:normal;"><span style="word-break: break-word; line-height: 32px;">Go to OptScale</span></span></a>
198+
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}?organizationId={{texts.organization.id}}" style="height:42px;width:149px;v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#f58535"><w:anchorlock/><v:textbox inset="0px,0px,0px,0px"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]-->
199+
<a href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}?organizationId={{texts.organization.id}}" target="_blank" rel="noopener" style="text-decoration:none;display:inline-block;color:#ffffff;background-color:#f58535;border-radius:4px;width:auto;border-top:0px solid #F58535;font-weight:400;border-right:0px solid #F58535;border-bottom:0px solid #F58535;border-left:0px solid #F58535;padding-top:5px;padding-bottom:5px;font-family:Arial, Helvetica Neue, Helvetica, sans-serif;text-align:center;mso-border-alt:none;word-break:keep-all;"><span style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;letter-spacing:normal;"><span style="word-break: break-word; line-height: 32px;">Go to OptScale</span></span></a>
199200
<!--[if mso]></center></v:textbox></v:roundrect><![endif]-->
200201
</div>
201202
</td>

herald/modules/email_generator/templates/organization_policy_quota.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@
195195
<tr>
196196
<td class="pad">
197197
<div class="alignment" align="center">
198-
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}" style="height:42px;width:149px;v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#f58535"><w:anchorlock/><v:textbox inset="0px,0px,0px,0px"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]--><a href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}" target="_blank" rel="noopener" style="text-decoration:none;display:inline-block;color:#ffffff;background-color:#f58535;border-radius:4px;width:auto;border-top:0px solid #F58535;font-weight:400;border-right:0px solid #F58535;border-bottom:0px solid #F58535;border-left:0px solid #F58535;padding-top:5px;padding-bottom:5px;font-family:Arial, Helvetica Neue, Helvetica, sans-serif;text-align:center;mso-border-alt:none;word-break:keep-all;"><span style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;letter-spacing:normal;"><span dir="ltr" style="word-break: break-word; line-height: 32px;">Go to OptScale</span></span></a>
198+
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}?organizationId={{texts.organization.id}}" style="height:42px;width:149px;v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#f58535"><w:anchorlock/><v:textbox inset="0px,0px,0px,0px"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]-->
199+
<a href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}?organizationId={{texts.organization.id}}" target="_blank" rel="noopener" style="text-decoration:none;display:inline-block;color:#ffffff;background-color:#f58535;border-radius:4px;width:auto;border-top:0px solid #F58535;font-weight:400;border-right:0px solid #F58535;border-bottom:0px solid #F58535;border-left:0px solid #F58535;padding-top:5px;padding-bottom:5px;font-family:Arial, Helvetica Neue, Helvetica, sans-serif;text-align:center;mso-border-alt:none;word-break:keep-all;"><span style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;letter-spacing:normal;"><span dir="ltr" style="word-break: break-word; line-height: 32px;">Go to OptScale</span></span></a>
199200
<!--[if mso]></center></v:textbox></v:roundrect><![endif]-->
200201
</div>
201202
</td>

herald/modules/email_generator/templates/organization_policy_recurring_budget.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@
195195
<tr>
196196
<td class="pad">
197197
<div class="alignment" align="center">
198-
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}" style="height:42px;width:149px;v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#f58535"><w:anchorlock/><v:textbox inset="0px,0px,0px,0px"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]--><a href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}" target="_blank" rel="noopener" style="text-decoration:none;display:inline-block;color:#ffffff;background-color:#f58535;border-radius:4px;width:auto;border-top:0px solid #F58535;font-weight:400;border-right:0px solid #F58535;border-bottom:0px solid #F58535;border-left:0px solid #F58535;padding-top:5px;padding-bottom:5px;font-family:Arial, Helvetica Neue, Helvetica, sans-serif;text-align:center;mso-border-alt:none;word-break:keep-all;"><span style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;letter-spacing:normal;"><span style="word-break: break-word; line-height: 32px;">Go to OptScale</span></span></a>
198+
<!--[if mso]><v:roundrect xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="urn:schemas-microsoft-com:office:word" href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}?organizationId={{texts.organization.id}}" style="height:42px;width:149px;v-text-anchor:middle;" arcsize="10%" stroke="false" fillcolor="#f58535"><w:anchorlock/><v:textbox inset="0px,0px,0px,0px"><center style="color:#ffffff; font-family:Arial, sans-serif; font-size:16px"><![endif]-->
199+
<a href="https://{{etcd.control_panel_link}}/policies/{{texts.organization_constraint.id}}?organizationId={{texts.organization.id}}" target="_blank" rel="noopener" style="text-decoration:none;display:inline-block;color:#ffffff;background-color:#f58535;border-radius:4px;width:auto;border-top:0px solid #F58535;font-weight:400;border-right:0px solid #F58535;border-bottom:0px solid #F58535;border-left:0px solid #F58535;padding-top:5px;padding-bottom:5px;font-family:Arial, Helvetica Neue, Helvetica, sans-serif;text-align:center;mso-border-alt:none;word-break:keep-all;"><span style="padding-left:20px;padding-right:20px;font-size:16px;display:inline-block;letter-spacing:normal;"><span style="word-break: break-word; line-height: 32px;">Go to OptScale</span></span></a>
199200
<!--[if mso]></center></v:textbox></v:roundrect><![endif]-->
200201
</div>
201202
</td>

insider/insider_api/controllers/flavor_price.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,7 @@ def __init__(self, config_cl):
8282
'sql web': 'SQL Web',
8383
'sql ent': 'SQL Ent'
8484
}
85-
self.region_map = {
86-
'ap-northeast-2': 'Asia Pacific (Seoul)',
87-
'eu-north-1': 'EU (Stockholm)',
88-
'eu-central-1': 'EU (Frankfurt)',
89-
'us-east-1': 'US East (N. Virginia)',
90-
'eu-west-1': 'EU (Ireland)',
91-
'me-south-1': 'Middle East (Bahrain)',
92-
'us-west-1': 'US West (N. California)',
93-
'ap-northeast-3': 'Asia Pacific (Osaka-Local)',
94-
'ca-central-1': 'Canada (Central)',
95-
'us-west-2': 'US West (Oregon)',
96-
'ap-southeast-2': 'Asia Pacific (Sydney)',
97-
'us-east-2': 'US East (Ohio)',
98-
'ap-northeast-1': 'Asia Pacific (Tokyo)',
99-
'eu-west-3': 'EU (Paris)',
100-
'ap-southeast-1': 'Asia Pacific (Singapore)',
101-
'eu-west-2': 'EU (London)',
102-
'af-south-1': 'Africa (Cape Town)',
103-
'ap-east-1': 'Asia Pacific (Hong Kong)',
104-
'eu-south-1': 'EU (Milan)',
105-
'ap-south-1': 'Asia Pacific (Mumbai)',
106-
'sa-east-1': 'South America (Sao Paulo)'
107-
}
85+
self._region_map = None
10886

10987
@property
11088
def cloud_adapter(self):
@@ -113,6 +91,16 @@ def cloud_adapter(self):
11391
self._cloud_adapter = Aws(config)
11492
return self._cloud_adapter
11593

94+
@property
95+
def region_map(self):
96+
if self._region_map is None:
97+
self._region_map = {}
98+
coord_map = self.cloud_adapter.get_regions_coordinates()
99+
for region, data in coord_map.items():
100+
if 'name' in data:
101+
self._region_map[region] = data['name']
102+
return self._region_map
103+
116104
@property
117105
def prices_collection(self):
118106
return self.mongo_client.restapi.aws_prices

insider/insider_api/tests/unittests/test_flavor_prices.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def setUp(self):
4141
self.aws_cad = patch(
4242
'insider.insider_api.controllers.flavor_price.'
4343
'AwsProvider.cloud_adapter').start()
44+
patch(
45+
'insider.insider_api.controllers.flavor_price.'
46+
'AwsProvider.cloud_adapter.get_regions_coordinates',
47+
return_value={'us-west-2': {'name': 'US West (Oregon)'}}
48+
).start()
4449
self.alibaba_cad = patch(
4550
'insider.insider_api.controllers.flavor_price.'
4651
'AlibabaProvider.cloud_adapter').start()

katara/katara_service/controllers/task.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ def edit(self, item_id, **kwargs):
9797
task.completed_at = now
9898
self.session.add(task)
9999
# child obj changes are possible only if obj in session
100-
task.schedule.last_run = now
100+
if task.schedule:
101+
task.schedule.last_run = now
101102
self.session.add(task)
102103
self.session.commit()
103104
except IntegrityError as ex:

katara/katara_service/tests/unittests/test_api_task.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,11 @@ def test_task_create_completed(self, _p_put_tasks):
150150
}
151151
code, _ = self.client.tasks_create([task_payload])
152152
self.assertEqual(code, 400)
153+
154+
@patch(PUT_TASK)
155+
def test_task_update_completed_no_schedule(self, _p_put_tasks):
156+
tasks = self.generate_tasks(1)
157+
self.client.schedule_delete(tasks[0].schedule_id)
158+
code, _ = self.client.task_update(
159+
tasks[0].id, state='completed')
160+
self.assertEqual(code, 200)

0 commit comments

Comments
 (0)