/
test_integration_dtrs.py
187 lines (151 loc) · 5.52 KB
/
test_integration_dtrs.py
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
import os
import uuid
import unittest
import logging
from dashi import DashiError
from nose.plugins.skip import SkipTest
try:
from epuharness.harness import EPUHarness
from epuharness.fixture import TestFixture
except ImportError:
raise SkipTest("epuharness not available.")
try:
from epu.mocklibcloud import MockEC2NodeDriver # noqa
except ImportError:
raise SkipTest("sqlalchemy not available.")
log = logging.getLogger(__name__)
default_user = 'default'
basic_deployment = """
process-dispatchers:
pd_0:
config:
processdispatcher:
engines:
default:
deployable_type: eeagent
slots: 4
base_need: 1
epums:
epum_0:
config:
epumanagement:
default_user: %(default_user)s
provisioner_service_name: prov_0
logging:
handlers:
file:
filename: /tmp/epum_0.log
provisioners:
prov_0:
config:
provisioner:
default_user: %(default_user)s
dt_registries:
dtrs:
config: {}
"""
fake_credentials = {
'access_key': 'xxx',
'secret_key': 'xxx',
'key_name': 'ooi'
}
dt_name = "example"
example_dt = {
'mappings': {
'ec2-fake': {
'iaas_image': 'ami-fake',
'iaas_allocation': 't1.micro',
}
},
'contextualization': {
'method': 'chef-solo',
'chef_config': {}
}
}
g_epuharness = None
g_deployment = basic_deployment % {"default_user": default_user}
def setUpModule():
epuh_persistence = "/tmp/SupD/epuharness"
if os.path.exists(epuh_persistence):
raise SkipTest("EPUHarness running. Can't run this test")
global g_epuharness
exchange = "testexchange-%s" % str(uuid.uuid4())
g_epuharness = EPUHarness(exchange=exchange)
g_epuharness.start(deployment_str=g_deployment)
def tearDownModule():
global g_epuharness
g_epuharness.stop()
class TestIntegrationDTRS(unittest.TestCase, TestFixture):
def setUp(self):
if not os.environ.get('INT'):
raise SkipTest("Slow integration test")
self.user = default_user
clients = self.get_clients(g_deployment, g_epuharness.dashi)
self.dtrs_client = clients['dtrs']
self.block_until_ready(g_deployment, g_epuharness.dashi)
def dtrs_simple_add_remove_test(self):
new_dt_name = str(uuid.uuid4())
self.dtrs_client.add_dt(self.user, new_dt_name, example_dt)
dts = self.dtrs_client.list_dts(self.user)
self.assertTrue(new_dt_name in dts, "The name %s was not found in %s" % (new_dt_name, str(dts)))
self.dtrs_client.remove_dt(self.user, new_dt_name)
dts = self.dtrs_client.list_dts(self.user)
self.assertFalse(new_dt_name in dts, "The name %s should not have been found" % (new_dt_name))
def dtrs_simple_add_describe_remove_test(self):
new_dt_name = str(uuid.uuid4())
self.dtrs_client.add_dt(self.user, new_dt_name, example_dt)
desc = self.dtrs_client.describe_dt(self.user, new_dt_name)
self.assertEquals(example_dt, desc, "The 2 dts did not match ||| %s ||| %s" % (str(desc), str(example_dt)))
self.dtrs_client.remove_dt(self.user, new_dt_name)
def dtrs_simple_add_update_remove_test(self):
new_dt_name = str(uuid.uuid4())
self.dtrs_client.add_dt(self.user, new_dt_name, example_dt)
desc = self.dtrs_client.describe_dt(self.user, new_dt_name)
key = unicode(uuid.uuid4())
val = unicode(uuid.uuid4())
desc[key] = val
self.dtrs_client.update_dt(self.user, new_dt_name, desc)
new_desc = self.dtrs_client.describe_dt(self.user, new_dt_name)
self.assertEqual(new_desc[key], val)
self.assertEqual(desc, new_desc, "The 2 dts did not match ||| %s ||| %s" % (str(desc), str(new_desc)))
self.dtrs_client.remove_dt(self.user, new_dt_name)
def dtrs_simple_add_same_twice_remove_test(self):
new_dt_name = str(uuid.uuid4())
self.dtrs_client.add_dt(self.user, new_dt_name, example_dt)
passed = False
try:
self.dtrs_client.add_dt(self.user, new_dt_name, example_dt)
except DashiError:
passed = True
self.assertTrue(passed, "an exception should have been raised")
self.dtrs_client.remove_dt(self.user, new_dt_name)
def dtrs_remove_dt_that_doesnt_exist_test(self):
new_dt_name = str(uuid.uuid4())
passed = False
try:
self.dtrs_client.remove_dt(self.user, new_dt_name)
except DashiError:
passed = True
self.assertTrue(passed, "an exception should have been raised")
def dtrs_remove_dt_twice_exist_test(self):
new_dt_name = str(uuid.uuid4())
self.dtrs_client.add_dt(self.user, new_dt_name, example_dt)
self.dtrs_client.remove_dt(self.user, new_dt_name)
passed = False
try:
self.dtrs_client.remove_dt(self.user, new_dt_name)
except DashiError:
passed = True
self.assertTrue(passed, "an exception should have been raised")
def dtrs_update_dt_that_doesnt_exist_test(self):
new_dt_name = str(uuid.uuid4())
passed = False
try:
self.dtrs_client.update_dt(self.user, new_dt_name, example_dt)
except DashiError:
passed = True
self.assertTrue(passed, "an exception should have been raised")
def dtrs_describe_dt_that_doesnt_exist_test(self):
new_dt_name = str(uuid.uuid4())
dt = self.dtrs_client.describe_dt(self.user, new_dt_name)
self.assertEqual(dt, None)