1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Networking API Test (Security Groups)"""
18
19
20 from yakumo.smoketest import *
21 from yakumo import utils
22
23
24 CIDR = '192.168.35.0/24'
25 GATEWAY_IP = '192.168.35.254'
26 FIXED_IP = '192.168.35.100'
27
28
30
31 LOG.info("Create Security Group #1")
32 name = get_random_str('security_group')
33 with c.security_group.create(name=name,
34 description='securty group 1') as sg:
35
36 LOG.debug("list security groups: %s",
37 [_.name for _ in c.security_group.list()])
38
39 test("Security Group #1 name is " + name, sg.name == name)
40
41 LOG.debug("list rules: %s",
42 [(_.direction, _.port_range_min, _.protocol)
43 for _ in sg.rules.list()])
44
45 LOG.info("Create Rule #1")
46 with sg.rules.create(direction='ingress',
47 ethertype='IPv4',
48 port_range_min=22,
49 port_range_max=22,
50 protocol='tcp',
51 remote_ip_prefix='0.0.0.0/0') as sgr:
52
53 LOG.debug("list rules: %s",
54 [(_.direction, _.port_range_min, _.protocol)
55 for _ in sg.rules.list()])
56
57 test("Security Group #1 has 3 rules", len(sg.rules.list()) == 3)
58
59 test("Rule #1 direction", sgr.direction == 'ingress')
60 test("Rule #1 ethertype", sgr.ethertype == 'IPv4')
61 test("Rule #1 port_range_min", sgr.port_range_min == 22)
62 test("Rule #1 port_range_max", sgr.port_range_max == 22)
63 test("Rule #1 protocol", sgr.protocol == 'tcp')
64 test("Rule #1 remote_ip_prefix",
65 sgr.remote_ip_prefix == '0.0.0.0/0')
66
67 test("Rule #1 is gone", sgr not in sg.rules.list())
68
69 LOG.debug("list rules: %s",
70 [(_.direction, _.port_range_min, _.protocol)
71 for _ in sg.rules.list()])
72
73 test("security_group #1 is gone", sg not in c.security_group.list())
74
75
76 if __name__ == '__main__':
77 c = utils.get_client()
78
79 LOG.debug("list security groups: %s",
80 [_.name for _ in c.security_group.list()])
81 main(c)
82 LOG.debug("list security_groups: %s",
83 [_.name for _ in c.security_group.list()])
84
85 show_test_summary()
86