| schillinge | 9622199 | 2019-03-14 22:41:52 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # Copyright (c) 2019 Erik Schilling |
| 3 | # ALL RIGHTS RESERVED. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import csv |
| 18 | import logging |
| 19 | import os |
| 20 | import subprocess |
| 21 | |
| 22 | import shutil |
| 23 | import time |
| 24 | |
| 25 | from emuvim.api.osm.pre_configured_osm import PreConfiguredOSM |
| 26 | from emuvim.api.util.docker_utils import build_dockerfile_dir |
| 27 | from mininet.log import setLogLevel |
| 28 | |
| 29 | logging.basicConfig(level=logging.DEBUG) |
| 30 | setLogLevel('debug') # set Mininet loglevel |
| 31 | logging.getLogger('werkzeug').setLevel(logging.DEBUG) |
| 32 | logging.getLogger('api.openstack.base').setLevel(logging.DEBUG) |
| 33 | logging.getLogger('api.openstack.compute').setLevel(logging.DEBUG) |
| 34 | logging.getLogger('api.openstack.keystone').setLevel(logging.DEBUG) |
| 35 | logging.getLogger('api.openstack.nova').setLevel(logging.DEBUG) |
| 36 | logging.getLogger('api.openstack.neutron').setLevel(logging.DEBUG) |
| 37 | logging.getLogger('api.openstack.heat').setLevel(logging.DEBUG) |
| 38 | logging.getLogger('api.openstack.heat.parser').setLevel(logging.DEBUG) |
| 39 | logging.getLogger('api.openstack.glance').setLevel(logging.DEBUG) |
| 40 | logging.getLogger('api.openstack.helper').setLevel(logging.DEBUG) |
| 41 | |
| 42 | prefix = os.path.dirname(os.path.abspath(__file__)) |
| 43 | |
| 44 | build_dockerfile_dir('../images/sshcontainer/', 'sshcontainer') |
| 45 | |
| 46 | layers_folder = os.path.join(prefix, '../charms/layers') |
| 47 | simple_charm_folder = os.path.join(layers_folder, 'simple') |
| 48 | charm_target_dir = os.path.join(prefix, '../vnfs/simple_charmed_vnfd/charms/') |
| 49 | shutil.rmtree(charm_target_dir, ignore_errors=True) |
| 50 | if not subprocess.call(['/snap/bin/charm', 'build'], cwd=simple_charm_folder, env={ |
| 51 | 'CHARM_BUILD_DIR': charm_target_dir, |
| 52 | 'CHARM_LAYERS_DIR': layers_folder |
| 53 | }) in [0, 100]: # 100 means tests skipped |
| 54 | raise RuntimeError('charm build failed') |
| 55 | |
| 56 | |
| 57 | def get_detailed_configuration_status(osm): |
| 58 | status = osm.ns_get(ns_id)['_admin']['deployed']['VCA'][0]['detailed-status'] |
| 59 | print('current status: %s' % status) |
| 60 | return status |
| 61 | |
| 62 | |
| 63 | def wait_for_detailed_configuration_status(osm, status): |
| 64 | while get_detailed_configuration_status(osm) != status: |
| 65 | time.sleep(1) |
| 66 | |
| 67 | |
| 68 | with open('charmed-%d.csv' % time.time(), 'w') as csvfile: |
| 69 | fieldnames = ['ns_create', 'charm_deployment_start', 'waiting_for_machine', 'installing_charm_software', |
| 70 | 'ns_action', 'ns_delete'] |
| 71 | writer = csv.DictWriter(csvfile, fieldnames=fieldnames) |
| 72 | writer.writeheader() |
| 73 | |
| 74 | for n in range(1, 10 + 1): |
| 75 | with PreConfiguredOSM() as osm: |
| 76 | osm.onboard_vnfd('../vnfs/simple_charmed_vnfd') |
| 77 | nsd_id = osm.onboard_nsd('../services/simple_charmed_nsd') |
| 78 | ns_create = time.time() |
| 79 | ns_id = osm.ns_create('charmed-ns-%d' % n, nsd_id) |
| 80 | osm.ns_wait_until_all_in_status('running') |
| 81 | ns_created = time.time() |
| 82 | |
| 83 | wait_for_detailed_configuration_status(osm, 'waiting for machine') |
| 84 | waiting_for_machine_start = time.time() |
| 85 | |
| 86 | wait_for_detailed_configuration_status(osm, 'installing charm software') |
| 87 | installing_charm_start = time.time() |
| 88 | |
| 89 | wait_for_detailed_configuration_status(osm, 'Ready!') |
| 90 | ready = time.time() |
| 91 | |
| 92 | instance = osm.api.compute.find_server_by_name_or_id('dc1_charmed-ns-%d-1--1' % n).emulator_compute |
| 93 | osm.ns_action(ns_id, 1, 'touch') |
| 94 | while instance.cmd('cat /testmanual') != '': |
| 95 | time.sleep(0.1) |
| 96 | ns_action_done = time.time() |
| 97 | |
| 98 | osm.ns_delete(ns_id) |
| 99 | osm.ns_wait_until_all_in_status('terminated') |
| 100 | ns_deleted = time.time() |
| 101 | |
| 102 | writer.writerow({ |
| 103 | 'ns_create': ns_created - ns_create, |
| 104 | 'charm_deployment_start': waiting_for_machine_start - ns_created, |
| 105 | 'waiting_for_machine': installing_charm_start - waiting_for_machine_start, |
| 106 | 'installing_charm_software': ready - installing_charm_start, |
| 107 | 'ns_action': ns_action_done - ready, |
| 108 | 'ns_delete': ns_deleted - ns_action_done, |
| 109 | }) |
| 110 | csvfile.flush() |