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

Source Code for Module yakumo.smoketests.st30_network_subnet_port

 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 (Networks/Subnets/Ports)""" 
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 Network #1") 32 name = get_random_str('network') 33 with c.network.create(name=name, is_shared=False) as n: 34 35 LOG.debug("list networks: %s", [_.name for _ in c.network.list()]) 36 37 LOG.debug("wait for created") 38 n.wait_for_finished() 39 test("Network #1 name is " + name, n.name == name) 40 test("Network #1 is active", n.status == 'ACTIVE') 41 42 LOG.info("Create Subnet #1") 43 name = get_random_str('subnet') 44 with c.subnet.create(name=name, 45 network=n, 46 ip_version=4, 47 cidr=CIDR, 48 gateway_ip=GATEWAY_IP, 49 is_dhcp_enabled=True) as s: 50 51 LOG.debug("list subnets: %s", [_.name for _ in c.subnet.list()]) 52 53 test("Subnet #1 name is " + name, s.name == name) 54 55 LOG.info("Create Port #1") 56 name = get_random_str('port') 57 with c.port.create(name=name, network=n) as p1: 58 59 LOG.debug("list ports: %s", [_.name for _ in c.port.list()]) 60 61 test("Port #1 name is " + name, p1.name == name) 62 63 test("Port #1 is gone", p1 not in c.port.list()) 64 65 LOG.info("Create Port #2") 66 name = get_random_str('port') 67 with c.port.create(name=name, 68 fixed_ips=[{ 69 'ip_address': FIXED_IP, 70 'subnet': s}], 71 network=n) as p2: 72 73 LOG.debug("list ports: %s", [_.name for _ in c.port.list()]) 74 75 test("Port #2 name is " + name, p2.name == name) 76 test("Port #2 has specified IP address", 77 FIXED_IP in [_['ip_address'] for _ in p2.fixed_ips]) 78 79 test("Port #2 is gone", p2 not in c.port.list()) 80 81 test("Subnet #1 is gone", s not in c.subnet.list()) 82 83 test("Network #1 is gone", n not in c.network.list())
84 85 86 if __name__ == '__main__': 87 c = utils.get_client() 88 89 LOG.debug("list networks: %s", [_.name for _ in c.network.list()]) 90 LOG.debug("list subnets: %s", [_.name for _ in c.subnet.list()]) 91 main(c) 92 LOG.debug("list networks: %s", [_.name for _ in c.network.list()]) 93 LOG.debug("list subnets: %s", [_.name for _ in c.subnet.list()]) 94 95 show_test_summary() 96