Package yakumo :: Package smoketests :: Module st31_security_group
[hide private]
[frames] | no frames]

Source Code for Module yakumo.smoketests.st31_security_group

 1  #!/usr/bin/env python 
 2  # 
 3  # Copyright 2014-2017 by Akira Yoshiyama <akirayoshiyama@gmail.com>. 
 4  # All Rights Reserved. 
 5  # 
 6  #    Licensed under the Apache License, Version 2.0 (the "License"); you may 
 7  #    not use this file except in compliance with the License. You may obtain 
 8  #    a copy of the License at 
 9  # 
10  #         http://www.apache.org/licenses/LICENSE-2.0 
11  # 
12  #    Unless required by applicable law or agreed to in writing, software 
13  #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 
14  #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 
15  #    License for the specific language governing permissions and limitations 
16  #    under the License. 
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   
29 -def main(c):
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