1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from oslo_config import cfg
11 from doctor_tests.identity_auth import get_identity_auth
12 from doctor_tests.identity_auth import get_session
13 from doctor_tests.os_clients import neutron_client
17 cfg.StrOpt('net_name',
19 help='the name of test net',
21 cfg.StrOpt('net_cidr',
22 default='192.168.168.0/24',
23 help='the cidr of test subnet',
28 class Network(object):
30 def __init__(self, conf, log):
33 self.auth = get_identity_auth(username=self.conf.doctor_user,
34 password=self.conf.doctor_passwd,
35 project=self.conf.doctor_project)
36 self.neutron = neutron_client(get_session(auth=self.auth))
41 self.log.info('network create start.......')
42 net_name = self.conf.net_name
43 networks = self.neutron.list_networks(name=net_name)['networks']
44 self.net = networks[0] if networks \
45 else self.neutron.create_network(
46 {'network': {'name': net_name}})['network']
47 self.log.info('network create end.......')
49 self.log.info('subnet create start.......')
50 subnets = self.neutron.list_subnets(network_id=self.net['id'])['subnets']
51 subnet_param = {'name': net_name, 'network_id': self.net['id'],
52 'cidr': self.conf.net_cidr, 'ip_version': 4,
54 self.subnet = subnets[0] if subnets \
55 else self.neutron.create_subnet(
56 {'subnet': subnet_param})['subnet']
57 self.log.info('subnet create end.......')
60 self.log.info('subnet delete start.......')
62 self.neutron.delete_subnet(self.subnet['id'])
63 self.log.info('subnet delete end.......')
65 self.log.info('network delete start.......')
67 self.neutron.delete_network(self.net['id'])
68 self.log.info('network delete end.......')