ChetanGaonker | 901727c | 2016-11-29 14:05:03 -0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2016-present Ciena Corporation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | import unittest |
| 17 | import os,sys |
| 18 | import os |
| 19 | import keystoneclient.v2_0.client as ksclient |
| 20 | import keystoneclient.apiclient.exceptions |
| 21 | import neutronclient.v2_0.client as nclient |
| 22 | import neutronclient.common.exceptions |
| 23 | import novaclient.v1_1.client as novaclient |
| 24 | from multiprocessing import Pool |
| 25 | from nose.tools import assert_equal |
| 26 | from CordLogger import CordLogger |
| 27 | |
| 28 | class cordvtn_exchange(CordLogger): |
| 29 | |
| 30 | app = 'org.opencord.cordvtn' |
| 31 | |
| 32 | @classmethod |
| 33 | def setUpClass(cls): |
| 34 | cls.olt = OltConfig() |
| 35 | cls.port_map, _ = cls.olt.olt_port_map() |
| 36 | if not cls.port_map: |
| 37 | cls.port_map = g_subscriber_port_map |
| 38 | cls.iface = cls.port_map[1] |
| 39 | |
| 40 | def setUp(self): |
| 41 | ''' Activate the cord vtn app''' |
| 42 | super(dhcp_exchange, self).setUp() |
| 43 | self.maxDiff = None ##for assert_equal compare outputs on failure |
| 44 | self.onos_ctrl = OnosCtrl(self.app) |
| 45 | status, _ = self.onos_ctrl.activate() |
| 46 | assert_equal(status, True) |
| 47 | time.sleep(3) |
| 48 | |
| 49 | def tearDown(self): |
| 50 | '''Deactivate the cord vtn app''' |
| 51 | self.onos_ctrl.deactivate() |
| 52 | super(dhcp_exchange, self).tearDown() |
| 53 | |
| 54 | def onos_load_config(self, config): |
| 55 | status, code = OnosCtrl.config(config) |
| 56 | if status is False: |
| 57 | log.info('JSON request returned status %d' %code) |
| 58 | assert_equal(status, True) |
| 59 | time.sleep(3) |
| 60 | |
| 61 | def create_tenant(tenant_name): |
| 62 | new_tenant = keystone.tenants.create(tenant_name=tenant_name, |
| 63 | description="CORD Tenant \ |
| 64 | created", |
| 65 | enabled=True) |
| 66 | tenant_id = new_tenant.id |
| 67 | tenant_status = True |
| 68 | user_data = [] |
| 69 | for j in range(2): |
| 70 | j += 1 |
| 71 | user_name = tenant_name + '-user-' + str(j) |
| 72 | user_data.append(create_user(user_name, tenant_id)) |
| 73 | |
| 74 | print " Tenant and User Created" |
| 75 | |
| 76 | tenant_data = {'tenant_name': tenant_name, |
| 77 | 'tenant_id': tenant_id, |
| 78 | 'status': tenant_status} |
| 79 | return tenant_data |
| 80 | |
| 81 | def create_user(user_name, tenant_id): |
| 82 | new_user = keystone.users.create(name=user_name, |
| 83 | password="ubuntu", |
| 84 | tenant_id=tenant_id) |
| 85 | print(' - Created User %s' % user_name) |
| 86 | keystone.roles.add_user_role(new_user, member_role, tenant_id) |
| 87 | if assign_admin: |
| 88 | admin_user = keystone.users.find(name='admin') |
| 89 | admin_role = keystone.roles.find(name='admin') |
| 90 | keystone.roles.add_user_role(admin_user, admin_role, tenant_id) |
| 91 | user_data = {'name': new_user.name, |
| 92 | 'id': new_user.id} |
| 93 | return user_data |
| 94 | |
| 95 | def delete_tenant(tenant_name): |
| 96 | tenant = keystone.tenants.find(name=tenant_name) |
| 97 | for j in range(2): |
| 98 | j += 1 |
| 99 | user_name = tenant_name + '-user-' + str(j) |
| 100 | delete_user(user_name, tenant.id) |
| 101 | tenant.delete() |
| 102 | print(' - Deleted Tenant %s ' % tenant_name) |
| 103 | return True |
| 104 | |
| 105 | def delete_user(user_name, tenant_id): |
| 106 | user = keystone.users.find(name=user_name) |
| 107 | user.delete() |
| 108 | |
| 109 | print(' - Deleted User %s' % user_name) |
| 110 | return True |
| 111 | |
| 112 | def get_neutron_credentials(): |
| 113 | d = {} |
| 114 | d['username'] = os.environ['OS_USERNAME'] |
| 115 | d['password'] = os.environ['OS_PASSWORD'] |
| 116 | d['auth_url'] = os.environ['OS_AUTH_URL'] |
| 117 | d['tenant_name'] = os.environ['OS_TENANT_NAME'] |
| 118 | return d |
| 119 | |
| 120 | |
| 121 | def create_network(i): |
| 122 | neutron_credentials = get_neutron_credentials() |
| 123 | neutron = neutron_client.Client(**neutron_credentials) |
| 124 | json = {'network': {'name': 'network-' + str(i), |
| 125 | 'admin_state_up': True}} |
| 126 | while True: |
| 127 | neutron.create_network(body=json) |
| 128 | print '\nnetwork-' + str(i) + ' created' |
| 129 | break |
| 130 | |
| 131 | pool = Pool(processes=5) |
| 132 | os.system("neutron quota-update --network 105") |
| 133 | for i in range(1,5): |
| 134 | pool.apply_async(create_network, (i, )) |
| 135 | pool.close() |
| 136 | pool.join() |
| 137 | |
| 138 | def test_cordvtn_basic_tenant(self): |
| 139 | pass |
| 140 | |
| 141 | def test_cordvtn_mgmt_network(self): |
| 142 | pass |
| 143 | |
| 144 | def test_cordvtn_data_network(self): |
| 145 | pass |
| 146 | |
| 147 | def test_cordvtn_public_network(self): |
| 148 | pass |
| 149 | |
| 150 | def test_cordvtn_in_same_network(self): |
| 151 | pass |
| 152 | |
| 153 | def test_cordvtn_local_mgmt_network(self): |
| 154 | pass |
| 155 | |
| 156 | def test_cordvtn_service_dependency(self): |
| 157 | pass |
| 158 | |
| 159 | def test_cordvtn_service_dependency_with_xos(self): |
| 160 | pass |
| 161 | |
| 162 | def test_cordvtn_vsg_xos_service_profile(self): |
| 163 | pass |
| 164 | |
| 165 | def test_cordvtn_access_agent(self): |
| 166 | pass |
| 167 | |
| 168 | def test_cordvtn_network_creation(self): |
| 169 | pass |
| 170 | |
| 171 | def test_cordvtn_removing_service_network(self): |
| 172 | pass |
| 173 | |
| 174 | def test_cordvtn_web_application(self): |
| 175 | pass |
| 176 | |
| 177 | def test_cordvtn_service_port(self): |
| 178 | pass |