Skip to content

Commit 1cdf53d

Browse files
author
Elias Nygren
committed
circleci integration tests
1 parent 99f48b3 commit 1cdf53d

File tree

10 files changed

+329
-310
lines changed

10 files changed

+329
-310
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.gitignore
12
__pycache__
23
ENV/
34
.DS_Store
@@ -9,7 +10,10 @@ dist/
910
*.sublime-workspace
1011
docs/html/
1112
.tox
13+
.cache
1214

1315
# pyenv
1416
.python-version
1517

18+
# local
19+
.test-snippets

circle.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
machine:
2+
python:
3+
# we want to run integration tests with 2.7.x
4+
# as it's the most important one due to Ansible
5+
version: 2.7.11
6+
7+
dependencies:
8+
override:
9+
- pip install tox tox-pyenv
10+
- pyenv install 2.6.9
11+
- pyenv local 2.6.9 2.7.11 3.3.6 3.4.4 3.5.1
12+
13+
test:
14+
override:
15+
- tox
16+
- tox -e py27 -- -x --integration-tests

requirements-dev.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
pytest==2.6.4
1+
pytest==2.9.2
22
py==1.4.26
3+
mock==1.0.1
4+
responses==0.3.0

requirements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
future==0.14.3
2-
mock==1.0.1
32
requests==2.6.0
4-
responses==0.3.0
53
six==1.9.0
64
wheel==0.24.0

test/conftest.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
from future import standard_library
77
standard_library.install_aliases()
88

9-
import json, os, pytest, responses
9+
import json, os, pytest, responses, sys
10+
11+
12+
# make files under helpers available for import
13+
HELPERS_PATH = os.path.join(os.path.dirname(__file__), 'helpers')
14+
sys.path.append(HELPERS_PATH)
15+
16+
17+
def pytest_addoption(parser):
18+
parser.addoption('--integration-tests', action='store_true', help='run integration tests')
19+
1020

1121
@pytest.fixture(scope='module')
1222
def manager():
@@ -84,11 +94,7 @@ def mock_server_operation(target):
8494
data = json.loads( Mock.read_from_file(targetfile + '.json') )
8595

8696
# API will always respond state: "started", see: Server.stop, Server.start, Server,restart
87-
data["server"]["state"] = "started"
97+
data['server']['state'] = 'started'
8898

8999
data = json.dumps( data )
90100
responses.add(responses.POST, Mock.base_url + "/" + target, status=200, body = data, content_type='application/json')
91-
92-
93-
94-

test/helpers/infra.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from __future__ import print_function
2+
from __future__ import unicode_literals
3+
from __future__ import division
4+
from __future__ import absolute_import
5+
from future import standard_library
6+
standard_library.install_aliases()
7+
8+
from upcloud_api import CloudManager, Storage, FirewallRule, ZONE, Tag
9+
from upcloud_api.server import Server, login_user_block
10+
11+
12+
CLUSTER = {
13+
'web1': Server(
14+
core_number = 1,
15+
memory_amount = 512,
16+
hostname = 'web1.example.com',
17+
zone = ZONE.London,
18+
password_delivery = 'none',
19+
storage_devices = [
20+
Storage(os = 'Ubuntu 14.04', size=10),
21+
Storage(size=10, tier='maxiops')
22+
]),
23+
24+
'web2': Server(
25+
core_number = 1,
26+
memory_amount = 512,
27+
hostname = 'web2.example.com',
28+
zone = ZONE.London,
29+
password_delivery = 'none',
30+
storage_devices = [
31+
Storage(os = 'Ubuntu 14.04', size=10),
32+
Storage(size=10, tier='maxiops'),
33+
]),
34+
35+
'db': Server(
36+
core_number = 1,
37+
memory_amount = 512,
38+
hostname = 'db.example.com',
39+
zone = ZONE.London,
40+
password_delivery = 'none',
41+
storage_devices = [
42+
Storage(os = 'CentOS 7.0', size=10),
43+
Storage(size=10),
44+
],
45+
login_user = login_user_block('testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x user@some.host'], True),
46+
),
47+
48+
49+
'lb': Server(
50+
plan= '1xCPU-1GB',
51+
hostname = 'balancer.example.com',
52+
zone = ZONE.London,
53+
password_delivery = 'none',
54+
storage_devices = [
55+
Storage(os = 'Debian 7.8', size=30)
56+
],
57+
login_user = login_user_block('testuser', ['ssh-rsa AAAAB3NzaC1yc2EAA[...]ptshi44x user@some.host'], True),
58+
)
59+
}
60+
61+
62+
FIREWALL_RULES = [
63+
FirewallRule(
64+
position = '1',
65+
direction = 'in',
66+
family = 'IPv4',
67+
protocol = 'tcp',
68+
source_address_start = '192.168.1.1',
69+
source_address_end = '192.168.1.255',
70+
destination_port_start = '22',
71+
destination_port_end = '22',
72+
action = 'accept'
73+
),
74+
FirewallRule(
75+
position = '2',
76+
direction = 'in',
77+
family = 'IPv4',
78+
protocol = 'tcp',
79+
source_address_start = '192.168.1.1',
80+
source_address_end = '192.168.1.255',
81+
destination_port_start = '21',
82+
destination_port_end = '21',
83+
action = 'accept'
84+
)
85+
]
86+
87+
88+
TAGS = [
89+
Tag('testlb'),
90+
Tag('testdb'),
91+
Tag('testweb')
92+
]

test/helpers/infra_helpers.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from __future__ import print_function
2+
from __future__ import unicode_literals
3+
from __future__ import division
4+
from __future__ import absolute_import
5+
from future import standard_library
6+
standard_library.install_aliases()
7+
8+
from upcloud_api import ZONE, Tag
9+
10+
def create_cluster(manager, cluster):
11+
"""Create all servers in cluster."""
12+
for server in cluster:
13+
s = manager.create_server(cluster[server])
14+
15+
for server in cluster:
16+
cluster[server].ensure_started()
17+
18+
return manager.get_servers()
19+
20+
21+
def firewall_test(manager, firewall_rules, server):
22+
"""Run tests on firewall rules."""
23+
# add 1 rule and remove it
24+
server.add_firewall_rule(firewall_rules[0])
25+
26+
fs = server.get_firewall_rules()
27+
assert len(fs) == 1
28+
29+
fs[0].destroy()
30+
fs = server.get_firewall_rules()
31+
assert len(fs) == 0
32+
33+
# add several rules and remove them
34+
server.configure_firewall(firewall_rules)
35+
36+
fs = server.get_firewall_rules()
37+
assert len(fs) == 2
38+
39+
for f in fs:
40+
manager.delete_firewall_rule(server.uuid, 1)
41+
42+
fs = server.get_firewall_rules()
43+
assert len(fs) == 0
44+
45+
46+
def server_test(manager, server):
47+
"""Run tests on a server instance."""
48+
server.populate()
49+
50+
server.core_number = '3'
51+
server.memory_amount = '1024'
52+
server.save()
53+
54+
server.add_IP()
55+
56+
storage = manager.create_storage(size=10, tier='maxiops', zone=ZONE.London)
57+
server.add_storage(storage)
58+
59+
server.start()
60+
61+
#sync new info from API and assert the changes from above have happened
62+
server.populate()
63+
assert server.core_number == '3'
64+
assert server.memory_amount == '1024'
65+
assert len(server.storage_devices) == 3
66+
assert len(server.ip_addresses) == 4
67+
68+
server.ensure_started()
69+
70+
71+
def tag_servers_test(manager, tags, cluster):
72+
"""Run tests on tags."""
73+
# create tags
74+
for t in tags:
75+
manager.create_tag(str(t))
76+
77+
cluster['web1'].add_tags(['testweb'])
78+
cluster['web2'].add_tags(['testweb'])
79+
cluster['lb'].add_tags([tags[1]]) # tags[1] is 'db'
80+
cluster['db'].add_tags(['testlb'])
81+
82+
fetched_servers = manager.get_servers(tags_has_one=['testlb'])
83+
assert len(fetched_servers) == 1
84+
assert fetched_servers[0].tags[0] == 'testlb'

0 commit comments

Comments
 (0)