1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
import base64
import json
import logging
import managers_mock as pdp_manager
import pytest
import requests_mock
CONF = {
"openstack": {
"keystone": {
"url": "http://keystone:5000/v3",
"user": "admin",
"check_token": False,
"password": "p4ssw0rd",
"domain": "default",
"certificate": False,
"project": "admin"
}
},
"components": {
"wrapper": {
"bind": "0.0.0.0",
"port": 8080,
"container": "wukongsun/moon_wrapper:v4.3",
"timeout": 5,
"hostname": "wrapper"
},
"manager": {
"bind": "0.0.0.0",
"port": 8082,
"container": "wukongsun/moon_manager:v4.3",
"hostname": "manager"
},
"port_start": 31001,
"orchestrator": {
"bind": "0.0.0.0",
"port": 8083,
"container": "wukongsun/moon_orchestrator:v4.3",
"hostname": "interface"
},
"interface": {
"bind": "0.0.0.0",
"port": 8080,
"container": "wukongsun/moon_interface:v4.3",
"hostname": "interface"
}
},
"plugins": {
"session": {
"port": 8082,
"container": "asteroide/session:latest"
},
"authz": {
"port": 8081,
"container": "wukongsun/moon_authz:v4.3"
}
},
"logging": {
"handlers": {
"file": {
"filename": "/tmp/moon.log",
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "custom",
"backupCount": 3,
"maxBytes": 1048576
},
"console": {
"class": "logging.StreamHandler",
"formatter": "brief",
"level": "INFO",
"stream": "ext://sys.stdout"
}
},
"formatters": {
"brief": {
"format": "%(levelname)s %(name)s %(message)-30s"
},
"custom": {
"format": "%(asctime)-15s %(levelname)s %(name)s %(message)s"
}
},
"root": {
"handlers": [
"console"
],
"level": "ERROR"
},
"version": 1,
"loggers": {
"moon": {
"handlers": [
"console",
"file"
],
"propagate": False,
"level": "DEBUG"
}
}
},
"slave": {
"name": None,
"master": {
"url": None,
"login": None,
"password": None
}
},
"docker": {
"url": "tcp://172.88.88.1:2376",
"network": "moon"
},
"database": {
"url": "sqlite:///database.db",
# "url": "mysql+pymysql://moon:p4sswOrd1@db/moon",
"driver": "sql"
},
"messenger": {
"url": "rabbit://moon:p4sswOrd1@messenger:5672/moon"
}
}
COMPONENTS = (
"logging",
"openstack/keystone",
"database",
"slave",
"components/manager",
"components/orchestrator",
"components/interface",
)
def get_b64_conf(component=None):
if component == "components":
return base64.b64encode(
json.dumps(CONF["components"]).encode('utf-8')+b"\n").decode('utf-8')
elif component in CONF:
return base64.b64encode(
json.dumps(
CONF[component]).encode('utf-8')+b"\n").decode('utf-8')
elif not component:
return base64.b64encode(
json.dumps(CONF).encode('utf-8')+b"\n").decode('utf-8')
elif "/" in component:
key1, _, key2 = component.partition("/")
return base64.b64encode(
json.dumps(
CONF[key1][key2]).encode('utf-8')+b"\n").decode('utf-8')
@pytest.fixture(autouse=True)
def no_requests(monkeypatch):
""" Modify the response from Requests module
"""
with requests_mock.Mocker(real_http=True) as m:
for component in COMPONENTS:
m.register_uri(
'GET', 'http://consul:8500/v1/kv/{}'.format(component),
json=[{'Key': component, 'Value': get_b64_conf(component)}]
)
m.register_uri(
'GET', 'http://consul:8500/v1/kv/components?recurse=true',
json=[
{"Key": key, "Value": get_b64_conf(key)} for key in COMPONENTS
],
# json={'Key': "components", 'Value': get_b64_conf("components")}
)
m.register_uri(
'POST', 'http://keystone:5000/v3/auth/tokens',
headers={'X-Subject-Token': "111111111"}
)
m.register_uri(
'DELETE', 'http://keystone:5000/v3/auth/tokens',
headers={'X-Subject-Token': "111111111"}
)
m.register_uri(
'POST', 'http://keystone:5000/v3/users?name=testuser&domain_id=default',
json={"users": {}}
)
m.register_uri(
'GET', 'http://keystone:5000/v3/users?name=testuser&domain_id=default',
json={"users": {}}
)
m.register_uri(
'POST', 'http://keystone:5000/v3/users/',
json={"users": [{
"id": "1111111111111"
}]}
)
pdp_manager.mock_managers(m)
print("End registering URI")
# from moon_db.db_manager import init_engine, run
# engine = init_engine()
# print("engine={}".format(engine))
# run("upgrade", logging.getLogger("db_manager"), engine)
# print("End populating the DB.")
yield m
# @pytest.fixture(autouse=True, scope="session")
# def manage_database():
# from moon_db.db_manager import init_engine, run
# engine = init_engine()
# run("upgrade", logging.getLogger("db_manager"), engine)
# yield
# print("Will close the DB")
|