/
test_integration_site.py
203 lines (166 loc) · 6.77 KB
/
test_integration_site.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import os
import uuid
import unittest
import logging
from dashi import DashiError
import tempfile
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
except ImportError:
raise SkipTest("sqlalchemy not available.")
from epu.test import ZooKeeperTestMixin
from epu.states import InstanceState
log = logging.getLogger(__name__)
default_user = 'default'
def make_fake_libcloud_site(site_name):
from epu.mocklibcloud import MockEC2NodeDriver
fh, fake_libcloud_db = tempfile.mkstemp()
os.close(fh)
fake_site = {
'name': site_name,
'description': 'Fake EC2',
'driver_class': 'epu.mocklibcloud.MockEC2NodeDriver',
'driver_kwargs': {
'sqlite_db': fake_libcloud_db
}
}
libcloud = MockEC2NodeDriver(sqlite_db=fake_libcloud_db)
return (fake_site, libcloud, fake_libcloud_db)
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 TestIntegrationSite(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 teardown(self):
os.remove(self.fake_libcloud_db)
def site_simple_add_remove_test(self):
name = str(uuid.uuid4())
(fake_site, lc, fake_libcloud_db) = make_fake_libcloud_site(name)
self.dtrs_client.add_site(fake_site['name'], fake_site)
sites = self.dtrs_client.list_sites()
self.assertTrue(fake_site['name'] in sites)
self.dtrs_client.remove_site(fake_site['name'])
def site_simple_add_describe_remove_test(self):
name = str(uuid.uuid4())
(fake_site, lc, fake_libcloud_db) = make_fake_libcloud_site(name)
self.dtrs_client.add_site(fake_site['name'], fake_site)
description = self.dtrs_client.describe_site(fake_site['name'])
self.assertEqual(fake_site, description, "These are not equal ||| %s ||| %s" % (str(description), str(fake_site)))
self.dtrs_client.remove_site(fake_site['name'])
def site_simple_add_update_remove_test(self):
name = str(uuid.uuid4())
(fake_site, lc, fake_libcloud_db) = make_fake_libcloud_site(name)
self.dtrs_client.add_site(fake_site['name'], fake_site)
description = self.dtrs_client.describe_site(fake_site['name'])
key = str(uuid.uuid4())
val = str(uuid.uuid4())
description[key] = val
self.dtrs_client.update_site(fake_site['name'], description)
new_description = self.dtrs_client.describe_site(fake_site['name'])
self.assertEqual(description, new_description)
self.dtrs_client.remove_site(fake_site['name'])
def site_simple_add_twice_test(self):
name = str(uuid.uuid4())
(fake_site, lc, fake_libcloud_db) = make_fake_libcloud_site(name)
self.dtrs_client.add_site(fake_site['name'], fake_site)
passed = False
try:
self.dtrs_client.add_site(fake_site['name'], fake_site)
except DashiError, de:
passed = True
self.assertTrue(passed, "An exception should have been raised")
self.dtrs_client.remove_site(fake_site['name'])
def site_simple_delete_no_there_test(self):
name = str(uuid.uuid4())
passed = False
try:
self.dtrs_client.remove_site(name)
except DashiError, de:
passed = True
self.assertTrue(passed, "An exception should have been raised")
def site_simple_update_no_there_test(self):
name = str(uuid.uuid4())
passed = False
try:
self.dtrs_client.update_site(name, {})
except DashiError, de:
passed = True
self.assertTrue(passed, "An exception should have been raised")
def site_simple_add_describe_not_exist_remove_test(self):
name = str(uuid.uuid4())
(fake_site, lc, fake_libcloud_db) = make_fake_libcloud_site(name)
passed = False
try:
description = self.dtrs_client.describe_site(name)
except DashiError, de:
passed = True
self.assertTrue(passed, "An exception should have been raised")