Skip to content

Commit e6f3258

Browse files
committed
fix: instack_env loop execution
closes: #504 Change-Id: I16e7174e04a6062164ad0a85ce85186434438910
1 parent 7ed66d7 commit e6f3258

3 files changed

Lines changed: 23 additions & 44 deletions

File tree

src/quads/tools/create_input_assignments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def print_summary():
128128
def get_json_link(cloud_name, filename, is_valid, style_tag_start, style_tag_end):
129129
if cloud_name == "cloud01":
130130
return ""
131-
_link = os.path.join(Config["quads_url"], "cloud", filename) if is_valid else "#"
131+
_link = os.path.join(Config["quads_url"], "instack", filename) if is_valid else "#"
132132
_text = "download" if is_valid else "validating"
133133
return "<a href=%s target=_blank>%s%s%s</a>" % (_link, style_tag_start, _text, style_tag_end)
134134

src/quads/tools/make_instackenv_json.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import asyncio
4+
import functools
45
import json
56
import os
67
import time
@@ -18,8 +19,7 @@
1819

1920

2021
async def make_env_json(filename):
21-
loop = asyncio.new_event_loop()
22-
asyncio.set_event_loop(loop)
22+
loop = asyncio.get_event_loop()
2323
foreman = Foreman(
2424
Config["foreman_api_url"],
2525
Config["foreman_username"],
@@ -35,10 +35,7 @@ async def make_env_json(filename):
3535
now = time.time()
3636
old_jsons = [file for file in os.listdir(Config["json_web_path"]) if ":" in file]
3737
for file in old_jsons:
38-
if (
39-
os.stat(os.path.join(Config["json_web_path"], file)).st_mtime
40-
< now - Config["json_retention_days"] * 86400
41-
):
38+
if os.stat(os.path.join(Config["json_web_path"], file)).st_mtime < now - Config["json_retention_days"] * 86400:
4239
os.remove(os.path.join(Config["json_web_path"], file))
4340

4441
for cloud in cloud_list:
@@ -53,9 +50,7 @@ async def make_env_json(filename):
5350
if Config["foreman_unavailable"]:
5451
overcloud = {"result": "true"}
5552
else:
56-
overcloud = loop.run_until_complete(
57-
foreman.get_host_param(host.name, "overcloud")
58-
)
53+
overcloud = await foreman.get_host_param(host.name, "overcloud")
5954

6055
if not overcloud:
6156
overcloud = {"result": "true"}
@@ -76,10 +71,7 @@ async def make_env_json(filename):
7671
if interface.pxe_boot:
7772
mac.append(interface.mac_address)
7873
if filename == "ocpinventory":
79-
mac = [
80-
interface.mac_address
81-
for interface in sorted(host.interfaces, key=lambda k: k.name)
82-
]
74+
mac = [interface.mac_address for interface in sorted(host.interfaces, key=lambda k: k.name)]
8375
data["nodes"].append(
8476
{
8577
"name": host.name,
@@ -105,9 +97,7 @@ async def make_env_json(filename):
10597
Config["json_web_path"],
10698
"%s_%s.json_%s" % (cloud.name, filename, now.strftime("%Y-%m-%d_%H:%M:%S")),
10799
)
108-
json_file = os.path.join(
109-
Config["json_web_path"], "%s_%s.json" % (cloud.name, filename)
110-
)
100+
json_file = os.path.join(Config["json_web_path"], "%s_%s.json" % (cloud.name, filename))
111101
with open(new_json_file, "w+") as _json_file:
112102
_json_file.seek(0)
113103
_json_file.write(content)
@@ -116,10 +106,20 @@ async def make_env_json(filename):
116106

117107

118108
def main():
109+
tasks = []
110+
loop = asyncio.get_event_loop()
111+
if not loop:
112+
loop = asyncio.new_event_loop()
113+
asyncio.set_event_loop(loop)
119114
if Config["openstack_management"]:
120-
asyncio.get_event_loop().run_until_complete(make_env_json("instackenv"))
115+
fn = functools.partial(make_env_json, "instackenv")
116+
tasks.append(fn)
121117
if Config["openshift_management"]:
122-
asyncio.get_event_loop().run_until_complete(make_env_json("ocpinventory"))
118+
fn = functools.partial(make_env_json, "ocpinventory")
119+
tasks.append(fn)
120+
loop.run_until_complete(asyncio.gather(*[task() for task in tasks]))
121+
122+
loop.close()
123123

124124

125125
if __name__ == "__main__":

tests/tools/test_instackenv.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,13 @@
99
class TestInstackenv(TestBase):
1010
def test_make_instackenv_json(self):
1111
Config.__setattr__("openstack_management", True)
12+
Config.__setattr__("openshift_management", True)
1213
Config.__setattr__("foreman_unavailable", True)
13-
Config.__setattr__(
14-
"json_web_path", os.path.join(os.path.dirname(__file__), "artifacts/")
15-
)
14+
Config.__setattr__("json_web_path", os.path.join(os.path.dirname(__file__), "artifacts/"))
1615
main()
17-
assert list(
18-
open(
19-
os.path.join(
20-
os.path.dirname(__file__), "artifacts/cloud99_instackenv.json"
21-
)
22-
)
23-
) == list(
16+
assert list(open(os.path.join(os.path.dirname(__file__), "artifacts/cloud99_instackenv.json"))) == list(
2417
open(os.path.join(os.path.dirname(__file__), "fixtures/cloud99_env.json"))
2518
)
26-
27-
def test_make_ocpinventory_json(self):
28-
Config.__setattr__("openshift_management", True)
29-
Config.__setattr__("foreman_unavailable", True)
30-
Config.__setattr__(
31-
"json_web_path", os.path.join(os.path.dirname(__file__), "artifacts/")
32-
)
33-
main()
34-
assert list(
35-
open(
36-
os.path.join(
37-
os.path.dirname(__file__), "artifacts/cloud99_ocpinventory.json"
38-
)
39-
)
40-
) == list(
19+
assert list(open(os.path.join(os.path.dirname(__file__), "artifacts/cloud99_ocpinventory.json"))) == list(
4120
open(os.path.join(os.path.dirname(__file__), "fixtures/cloud99_env.json"))
4221
)

0 commit comments

Comments
 (0)