Skip to content

Commit ac77ba8

Browse files
committed
Move admin API tests out of broker
Add support for manually specifying plugin package top level name Make plugin initiation more robust
1 parent 6184a6a commit ac77ba8

File tree

6 files changed

+248
-9
lines changed

6 files changed

+248
-9
lines changed

lib/features/admin.feature

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
# Created by nicklasborjesson at 30/05/16
1+
# Created by nibo at 2015-06-03
22
Feature: Administrative functions and interface
33
The admin web backend is basically just a web facing API frontend, broker restarting and similar features are actually
44
tested in the broker library implementation instead. Here, mostly UI-supporting functionality is tested
55

6-
Scenario: Generate initialisation file
7-
Given several plugins have loaded
8-
And refresh_init has been run
9-
Then admin_ui_init should be properly structured
6+
7+
Scenario: Starting broker and use the API to shut everything down
8+
Given the broker is started
9+
And we wait 2 seconds
10+
And it is it possible to register an admin at the broker
11+
And the broker is told to restart using the API
12+
And we wait 4 seconds
13+
And it is it possible to register an admin at the broker
14+
And the broker is told to stop using the API
15+
And we wait 2 seconds
16+
And a get environment request should fail
17+
18+
"""

lib/features/environment.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22
Initialization for OF broker tests.
33
"""
44
import os
5-
from admin.lib.admin import CherryPyAdmin
65

7-
__author__ = 'Nicklas Borjesson'
6+
from of.broker.testing.init_env import init_env
87

8+
__author__ = 'Nicklas Borjesson'
99

10+
# Test users uuids
11+
id_user_root = "000000010000010001e64c30"
12+
id_user_test = "000000010000010001e64c31"
1013

1114

1215
id_right_admin_nodes = "000000010000010001e64d01"
1316

1417
script_dir = os.path.dirname(__file__)
1518

1619
def before_all(context):
17-
_plugins =
1820

19-
context.admin = CherryPyAdmin(_address="test", _plugins=)
21+
os.environ["OPTIMAL_FW_CFG"] = os.path.join(script_dir, "steps", "config.json")
22+
init_env(_database_name = "test_admin", _context = context)
23+
2024

2125
def init_broker_cycles(context, feature):
2226
print("\nRunning Broker startup and shutdown scenarios\n=========================================================\n")

lib/features/steps/admin.py

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import os
2+
3+
import traceback
4+
from multiprocessing import Process
5+
import time
6+
7+
from behave import *
8+
from nose.tools.trivial import ok_
9+
10+
from of.broker.features import run_broker_testing
11+
from of.common.messaging.utils import call_api, register_at_broker
12+
13+
use_step_matcher("re")
14+
15+
_log_prefix = "Tester - Broker Cycles :"
16+
script_dir = os.path.dirname(__file__)
17+
18+
19+
20+
@given("the broker is started")
21+
def step_impl(context):
22+
"""
23+
:type context behave.runner.Context
24+
"""
25+
try:
26+
print(_log_prefix + "Starting broker process.")
27+
context.broker_process = Process(name="broker_testing", target=run_broker_testing, daemon=False)
28+
context.broker_process.start()
29+
if context.broker_process.exitcode:
30+
ok_(False, "Failed starting the process, it terminated within wait time.")
31+
else:
32+
ok_(True)
33+
except Exception as e:
34+
print(_log_prefix + "Error starting broker: " + str(e) + "\nTraceback:" + traceback.format_exc())
35+
ok_(False)
36+
37+
38+
39+
40+
41+
@then("a termination on linux should return zero as exit code")
42+
def step_impl(context):
43+
"""
44+
:type context behave.runner.Context
45+
"""
46+
print(_log_prefix + "Terminating the broker process")
47+
context.broker_process.terminate()
48+
try:
49+
context.broker_process.join(timeout=10)
50+
except:
51+
ok_(False, "Broker process did not exit within 5 seconds")
52+
if os.name == "nt":
53+
print("Terminations cannot be gracefully catched and acted upon on windows")
54+
ok_(True)
55+
else:
56+
if context.broker_process.exitcode != 0:
57+
ok_(False, "Broker process exited with a nonzero exit code: " + str(context.broker_process.exitcode))
58+
else:
59+
ok_(True)
60+
61+
62+
@step("the broker is told to restart using the API")
63+
def step_impl(context):
64+
"""
65+
:type context behave.runner.Context
66+
"""
67+
print(_log_prefix + "Telling Broker to restart using a call to broker_control...")
68+
call_api(_url="https://127.0.0.1:8080/admin/broker_control",
69+
_session_id=context.session["session_id"],
70+
_data={"command": "restart", "reason": "Testing restarting the broker"},
71+
_verify_SSL=False
72+
)
73+
print(_log_prefix + "Waiting for process to exit...")
74+
75+
context.broker_process.join(timeout=2)
76+
ok_(True)
77+
78+
@step("the broker is told to stop using the API")
79+
def step_impl(context):
80+
"""
81+
:type context behave.runner.Context
82+
"""
83+
print(_log_prefix + "Telling Broker to stop using a call to stop_broker...")
84+
call_api(_url="https://127.0.0.1:8080/admin/broker_control",
85+
_session_id=context.session["session_id"],
86+
_data={"command": "stop", "reason": "Testing stopping the broker"},
87+
_verify_SSL=False
88+
)
89+
ok_(True)
90+
91+
@step("a get environment request should fail")
92+
def step_impl(context):
93+
"""
94+
:type context behave.runner.Context
95+
"""
96+
try:
97+
_response = call_api(_url="https://127.0.0.1:8080/get_broker_environment",
98+
_session_id=context.session["session_id"],
99+
_data={}, _verify_SSL=False)
100+
except Exception as e:
101+
ok_(True, str(e))
102+
else:
103+
104+
os.kill(_response["systemPid"], 9)
105+
ok_(False, "The broker could still be reached after being told to shut down, killed pid "+ str(_response["systemPid"] + " manually."))
106+
107+
108+
@step("we wait (?P<seconds>.+) seconds")
109+
def step_impl(context, seconds):
110+
"""
111+
:type context behave.runner.Context
112+
"""
113+
time.sleep(float(seconds))
114+
ok_(True)
115+
116+
117+
@step("there is a web_socket peer with the address (?P<address>.+)")
118+
def step_impl(context, address):
119+
"""
120+
:type context behave.runner.Context
121+
"""
122+
print("Tester: Calling get_peers and checking for the address " + str(address))
123+
try:
124+
_peers = call_api(_url="https://127.0.0.1:8080/admin/get_peers",
125+
_session_id=context.session["session_id"],
126+
_data={}, _verify_SSL=False
127+
)
128+
except Exception as e:
129+
ok_(False, "An error occurred contacting server:" + str(e))
130+
if _peers:
131+
for _peer in _peers:
132+
133+
if "web_socket" in _peer and _peer["address"] == address and _peer["web_socket"] == "removed for serialization":
134+
ok_(True)
135+
return
136+
ok_(False, "No " + str(address) + " peer registered.")
137+
else:
138+
ok_(False, "No response from the server.")
139+
140+
141+
142+
@step("it is it possible to register an (?P<peer_type>.+) at the broker")
143+
def step_impl(context, peer_type):
144+
"""
145+
:type context behave.runner.Context
146+
"""
147+
148+
try:
149+
context.session = register_at_broker(_address="test", _type=peer_type, _server="https://127.0.0.1:8080",
150+
_username="tester", _password="test", _verify_SSL=False)
151+
152+
if context.session["session_id"]:
153+
print("Successfully registered at broker, got sessionid: " + str(context.session["session_id"]))
154+
ok_(True)
155+
else:
156+
ok_(False, "No session Id returned.")
157+
except ConnectionError as e:
158+
ok_(False, "'Connection Error registering:" + str(e))
159+
except Exception as e:
160+
ok_(False, "Error registering:" + str(e))
161+
162+

lib/features/steps/config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"broker": {
3+
"address": "broker01",
4+
"pluginFolder": "../../../../",
5+
"packageNameOverride": "admin",
6+
"database": {
7+
"databaseName": "test_admin"
8+
},
9+
"logging": {
10+
"severityLevel": "debug",
11+
"databaseLevel": "debug"
12+
}
13+
}
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDzzCCAregAwIBAgIJAMdpiQTFggwPMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNV
3+
BAYTAlNFMRIwEAYDVQQIDAlTdG9ja2hvbG0xEjAQBgNVBAcMCVN0b2NraG9sbTEU
4+
MBIGA1UECgwLT3B0aW1hbCBCUE0xCzAJBgNVBAsMAklUMSQwIgYJKoZIhvcNAQkB
5+
FhVuaWNrbGFzQG9wdGltYWxicG0uc2UwHhcNMTQxMDEwMDgzMjA2WhcNMTUxMDEw
6+
MDgzMjA2WjB+MQswCQYDVQQGEwJTRTESMBAGA1UECAwJU3RvY2tob2xtMRIwEAYD
7+
VQQHDAlTdG9ja2hvbG0xFDASBgNVBAoMC09wdGltYWwgQlBNMQswCQYDVQQLDAJJ
8+
VDEkMCIGCSqGSIb3DQEJARYVbmlja2xhc0BvcHRpbWFsYnBtLnNlMIIBIjANBgkq
9+
hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8XbKuUcoxhlX4c37T+gY7vnIdjRKgoUk
10+
YeoGVmrO9DMjwIJPYNbDdL/QdB2mrfEb7neKiWPSGEESJixr4qPq0VmMqob7Eea2
11+
tC8gURp7pfofDXsdHWYXF/ExsOCk7zrdNnm3TeGes1tKytzTEDjag6IRmPklfEXq
12+
NESwUlvelQP2GDb9LEnmRedDNI/1mU9u/79hp9QY6oLsmYAhYtomxCxBCnj+XjX8
13+
Sy4SlZcFHtGeZbtaUB1404gUgv0wsVW2rX7RZ0lFnhKLNKKyeT+moDZ+NvfXgVTa
14+
YuKaT9+UUVsi4KaigQbNLrvE+AX5zmBiRylDiHMVMGtPmg2Xdz1r4QIDAQABo1Aw
15+
TjAdBgNVHQ4EFgQUVc2KyfuvSGybHaXUWs5YeAQxC3QwHwYDVR0jBBgwFoAUVc2K
16+
yfuvSGybHaXUWs5YeAQxC3QwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOC
17+
AQEAp/ykY6bYUxnFdXeJMaTyl0GA07DgWiZHQucdLpZu4lqY2oCpnVKFgNj+klhb
18+
5n5FkWEspHqN4Nadokz398FLXAsbxLtUTcdizVmO6PCg98rGrWDuT2dRAMvf7PJ8
19+
eteHV4NybSirc640Kv+Y9+E59I9LNSy+uXy1YnpukZyT6a+69zwGSjZ+J2mN9uaX
20+
/738ENnId+9luCSk91yP5ZDKILscQPrw7C9GAxb+LYLRqH38/WWKJs4vT1QMkq9a
21+
XTCjas3pcCRSiiseVx0oeLt4Y9zcgbVQrSDYR60pD2ho7xz3tvzRCLW0bEW16kd6
22+
Qoc8FkB8peEMJKrKSg/FPsOolw==
23+
-----END CERTIFICATE-----
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpAIBAAKCAQEA8XbKuUcoxhlX4c37T+gY7vnIdjRKgoUkYeoGVmrO9DMjwIJP
3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