Skip to content

Commit 93d58a4

Browse files
authored
Merge pull request #84 from stfc/Handle_sandboxes_v2
Handle sandboxes v2
2 parents da6a8d2 + f483627 commit 93d58a4

File tree

8 files changed

+56
-79
lines changed

8 files changed

+56
-79
lines changed

OpenStack-Rabbit-Consumer/rabbit_consumer/aq_api.py

+12-28
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from rabbit_consumer.rabbit_message import RabbitMessage
1414
from rabbit_consumer.vm_data import VmData
1515

16-
MAKE_SUFFIX = "/host/{0}/command/make"
17-
1816
HOST_CHECK_SUFFIX = "/host/{0}"
1917

2018
UPDATE_INTERFACE_SUFFIX = "/machine/{0}/interface/{1}?boot&default_route"
@@ -84,21 +82,11 @@ def setup_requests(
8482
return response.text
8583

8684

87-
def aq_make(addresses: List[OpenstackAddress], image_meta: AqMetadata) -> None:
85+
def aq_make(addresses: List[OpenstackAddress]) -> None:
8886
"""
89-
Runs AQ make against a list of addresses passed to build the default personality
87+
Runs AQ make against a list of addresses passed to refresh
88+
the given host
9089
"""
91-
params = {
92-
"personality": image_meta.aq_personality,
93-
"osversion": image_meta.aq_os_version,
94-
"osname": image_meta.aq_os,
95-
"archetype": image_meta.aq_archetype,
96-
}
97-
98-
assert all(
99-
i for i in params.values()
100-
), "Some fields were not set in the OS description"
101-
10290
# Manage and make these back to default domain and personality
10391
address = addresses[0]
10492
hostname = address.hostname
@@ -107,8 +95,8 @@ def aq_make(addresses: List[OpenstackAddress], image_meta: AqMetadata) -> None:
10795
if not hostname or not hostname.strip():
10896
raise ValueError("Hostname cannot be empty")
10997

110-
url = ConsumerConfig().aq_url + MAKE_SUFFIX.format(hostname)
111-
setup_requests(url, "post", "Make Template: ", params)
98+
url = ConsumerConfig().aq_url + f"/host/{hostname}/command/make"
99+
setup_requests(url, "post", "Make Template")
112100

113101

114102
def aq_manage(addresses: List[OpenstackAddress], image_meta: AqMetadata) -> None:
@@ -121,9 +109,13 @@ def aq_manage(addresses: List[OpenstackAddress], image_meta: AqMetadata) -> None
121109

122110
params = {
123111
"hostname": hostname,
124-
"domain": image_meta.aq_domain,
125112
"force": True,
126113
}
114+
if image_meta.aq_sandbox:
115+
params["sandbox"] = image_meta.aq_sandbox
116+
else:
117+
params["domain"] = image_meta.aq_domain
118+
127119
url = ConsumerConfig().aq_url + f"/host/{hostname}/command/manage"
128120
setup_requests(url, "post", "Manage Host", params=params)
129121

@@ -158,14 +150,6 @@ def delete_machine(machine_name: str) -> None:
158150
setup_requests(url, "delete", "Delete Machine")
159151

160152

161-
def _is_sandbox(image_meta: AqMetadata) -> bool:
162-
"""
163-
Returns True if the image is a sandbox image
164-
we do a simple test for a '/' in the domain name
165-
"""
166-
return "/" in image_meta.aq_domain
167-
168-
169153
def create_host(
170154
image_meta: AqMetadata, addresses: List[OpenstackAddress], machine_name: str
171155
) -> None:
@@ -184,8 +168,8 @@ def create_host(
184168
"osversion": image_meta.aq_os_version,
185169
}
186170

187-
if _is_sandbox(image_meta):
188-
params["sandbox"] = image_meta.aq_domain
171+
if image_meta.aq_sandbox:
172+
params["sandbox"] = image_meta.aq_sandbox
189173
else:
190174
params["domain"] = image_meta.aq_domain
191175

OpenStack-Rabbit-Consumer/rabbit_consumer/aq_metadata.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22
from dataclasses import dataclass
3-
from typing import Dict
3+
from typing import Dict, Optional
44

55
from mashumaro import DataClassDictMixin
66
from mashumaro.config import BaseConfig
@@ -16,13 +16,14 @@ class AqMetadata(DataClassDictMixin):
1616
"""
1717

1818
aq_archetype: str
19-
# Aq domain can hold either a domain or sandbox reference
2019
aq_domain: str
2120

2221
aq_personality: str
2322
aq_os_version: str
2423
aq_os: str
2524

25+
aq_sandbox: Optional[str] = None
26+
2627
# pylint: disable=too-few-public-methods
2728
class Config(BaseConfig):
2829
"""
@@ -32,6 +33,7 @@ class Config(BaseConfig):
3233
aliases = {
3334
"aq_archetype": "AQ_ARCHETYPE",
3435
"aq_domain": "AQ_DOMAIN",
36+
"aq_sandbox": "AQ_SANDBOX",
3537
"aq_personality": "AQ_PERSONALITY",
3638
"aq_os_version": "AQ_OSVERSION",
3739
"aq_os": "AQ_OS",
@@ -45,6 +47,3 @@ def override_from_vm_meta(self, vm_meta: Dict[str, str]):
4547
for attr, alias in self.Config.aliases.items():
4648
if alias in vm_meta:
4749
setattr(self, attr, vm_meta[alias])
48-
49-
if "AQ_SANDBOX" in vm_meta:
50-
self.aq_domain = vm_meta["AQ_SANDBOX"]

OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ def handle_create_machine(rabbit_message: RabbitMessage) -> None:
160160

161161
# Manage host in Aquilon
162162
aq_api.create_host(image_meta, network_details, machine_name)
163-
164-
aq_api.aq_manage(network_details, image_meta)
165-
aq_api.aq_make(network_details, image_meta)
163+
aq_api.aq_make(network_details)
166164

167165
add_aq_details_to_metadata(vm_data, network_details)
168166

OpenStack-Rabbit-Consumer/test/test_aq_api.py

+31-34
Original file line numberDiff line numberDiff line change
@@ -130,45 +130,17 @@ def test_setup_requests_rest_methods(_, kerb_auth, requests, rest_verb):
130130

131131
@patch("rabbit_consumer.aq_api.setup_requests")
132132
@patch("rabbit_consumer.aq_api.ConsumerConfig")
133-
def test_aq_make_calls(config, setup, openstack_address_list, image_metadata):
133+
def test_aq_make_calls(config, setup, openstack_address_list):
134134
"""
135135
Test that aq_make calls the correct URLs with the correct parameters
136136
"""
137137
domain = "domain"
138138
config.return_value.aq_url = domain
139139

140-
aq_make(openstack_address_list, image_metadata)
141-
142-
expected_params = {
143-
"personality": image_metadata.aq_personality,
144-
"osversion": image_metadata.aq_os_version,
145-
"osname": image_metadata.aq_os,
146-
"archetype": image_metadata.aq_archetype,
147-
}
140+
aq_make(openstack_address_list)
148141

149142
expected_url = f"{domain}/host/{openstack_address_list[0].hostname}/command/make"
150-
setup.assert_called_once_with(expected_url, "post", mock.ANY, expected_params)
151-
152-
153-
@pytest.mark.parametrize(
154-
"field_to_blank",
155-
[
156-
"aq_personality",
157-
"aq_os_version",
158-
"aq_os",
159-
],
160-
)
161-
def test_aq_make_missing_fields(field_to_blank, openstack_address_list, image_metadata):
162-
"""
163-
Test that aq_make throws an exception when a required field is missing
164-
"""
165-
with pytest.raises(AssertionError):
166-
setattr(image_metadata, field_to_blank, None)
167-
aq_make(openstack_address_list, image_metadata)
168-
169-
with pytest.raises(AssertionError):
170-
setattr(image_metadata, field_to_blank, "")
171-
aq_make(openstack_address_list, image_metadata)
143+
setup.assert_called_once_with(expected_url, "post", mock.ANY)
172144

173145

174146
@pytest.mark.parametrize("hostname", [" ", "", None])
@@ -185,7 +157,7 @@ def test_aq_make_none_hostname(config, setup, openstack_address, hostname):
185157
address.hostname = hostname
186158

187159
with pytest.raises(ValueError):
188-
aq_make([address], NonCallableMock())
160+
aq_make([address])
189161

190162
setup.assert_not_called()
191163

@@ -211,6 +183,30 @@ def test_aq_manage(config, setup, openstack_address_list, image_metadata):
211183
setup.assert_called_once_with(expected_url, "post", mock.ANY, params=expected_param)
212184

213185

186+
@patch("rabbit_consumer.aq_api.setup_requests")
187+
@patch("rabbit_consumer.aq_api.ConsumerConfig")
188+
def test_aq_manage_with_sandbox(config, setup, openstack_address_list, image_metadata):
189+
"""
190+
Test that aq_manage calls the correct URLs with the sandbox
191+
instead of the domain
192+
"""
193+
config.return_value.aq_url = "https://example.com"
194+
195+
image_metadata.aq_sandbox = "some_sandbox"
196+
197+
aq_manage(openstack_address_list, image_metadata)
198+
address = openstack_address_list[0]
199+
200+
expected_param = {
201+
"hostname": address.hostname,
202+
"sandbox": image_metadata.aq_sandbox,
203+
"force": True,
204+
}
205+
206+
expected_url = f"https://example.com/host/{address.hostname}/command/manage"
207+
setup.assert_called_once_with(expected_url, "post", mock.ANY, params=expected_param)
208+
209+
214210
@patch("rabbit_consumer.aq_api.ConsumerConfig")
215211
@patch("rabbit_consumer.aq_api.setup_requests")
216212
def test_aq_create_machine(setup, config, rabbit_message, vm_data):
@@ -292,7 +288,8 @@ def test_aq_create_host_with_sandbox(
292288
env_config = config.return_value
293289
env_config.aq_url = "https://example.com"
294290

295-
image_metadata.aq_domain = "example/sandbox"
291+
image_metadata.aq_domain = "example_domain"
292+
image_metadata.aq_sandbox = "example/sandbox"
296293

297294
create_host(image_metadata, openstack_address_list, machine_name)
298295
address = openstack_address_list[0]
@@ -304,7 +301,7 @@ def test_aq_create_host_with_sandbox(
304301
"personality": image_metadata.aq_personality,
305302
"osname": image_metadata.aq_os,
306303
"osversion": image_metadata.aq_os_version,
307-
"sandbox": image_metadata.aq_domain,
304+
"sandbox": image_metadata.aq_sandbox,
308305
}
309306

310307
expected_url = f"https://example.com/host/{address.hostname}"

OpenStack-Rabbit-Consumer/test/test_aq_metadata.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def test_aq_metadata_override_all(image_metadata):
5555
assert returned.aq_os_version == "osversion_mock"
5656

5757

58-
def test_aq_metadata_override_sandbox(image_metadata):
58+
def test_aq_metadata_sandbox(image_metadata):
5959
"""
60-
Tests overriding the sandbox value in an AQ metadata object
61-
maps correctly onto the domain value
60+
Tests the sandbox value in an AQ metadata object
61+
maps correctly onto the sandbox value
6262
"""
6363
returned = AqMetadata.from_dict(image_metadata)
6464
returned.override_from_vm_meta(
@@ -67,7 +67,7 @@ def test_aq_metadata_override_sandbox(image_metadata):
6767
}
6868
)
6969
# This should be the only value that has changed
70-
assert returned.aq_domain == "sandbox_mock"
70+
assert returned.aq_sandbox == "sandbox_mock"
7171

7272
assert returned.aq_archetype == "archetype_mock"
7373
assert returned.aq_personality == "personality_mock"

OpenStack-Rabbit-Consumer/test/test_message_consumer.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,7 @@ def test_consume_create_machine_hostnames_good_path(
248248
aq_api.create_host.assert_called_once_with(
249249
image_metadata, network_details, machine_name
250250
)
251-
aq_api.aq_manage.assert_called_once_with(network_details, image_metadata)
252-
aq_api.aq_make.assert_called_once_with(network_details, image_metadata)
251+
aq_api.aq_make.assert_called_once_with(network_details)
253252

254253
# Metadata
255254
metadata.assert_called_once_with(vm_data, network_details)

OpenStack-Rabbit-Consumer/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.3
1+
2.3.4

charts/rabbit-consumer/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ type: application
66
# This is the chart version. This version number should be incremented each time you make changes
77
# to the chart and its templates, including the app version.
88
# Versions are expected to follow Semantic Versioning (https://semver.org/)
9-
version: 1.4.3
9+
version: 1.4.4
1010

1111
# This is the version number of the application being deployed. This version number should be
1212
# incremented each time you make changes to the application. Versions are not expected to
1313
# follow Semantic Versioning. They should reflect the version the application is using.
1414
# It is recommended to use it with quotes.
15-
appVersion: "v2.3.3"
15+
appVersion: "v2.3.4"
1616

0 commit comments

Comments
 (0)