def register_vm(vm_type="magma", admin_cert=( './../../.cache/test_certs/admin_operator.pem', './../../.cache/test_certs/admin_operator.key.pem')): """ Provisions the gateway vm with the cloud vm """ print('Please ensure that you did "make run" in both VMs! ' 'Linking gateway and cloud VMs...') with hide('output', 'running', 'warnings'): vagrant.setup_env_vagrant(vm_type) hardware_id = run('cat /etc/snowflake') print('Found Hardware ID for gateway: %s' % hardware_id) # Validate if we have the right admin certs _validate_certs(admin_cert) # Create the test network network_id = 'test' networks = _cloud_get('/networks', admin_cert) if network_id in networks: print('Test network already exists!') else: print('Creating a test network...') _cloud_post('/networks', data={'name': 'TestNetwork'}, params={'requested_id': network_id}, admin_cert=admin_cert) # Provision the gateway gateways = _cloud_get('/networks/%s/gateways' % network_id, admin_cert) gateway_id = 'gw' + str(len(gateways) + 1) print('Provisioning gateway as %s...' % gateway_id) data = _construct_gateway_object(gateway_id, hardware_id) _cloud_post('/networks/%s/gateways' % network_id, data=data, params={'requested_id': gateway_id}, admin_cert=admin_cert) print('Gateway successfully provisioned as: %s' % gateway_id)
def package(feg_host=None, vcs="hg", force=False): """ Create deploy package and push to S3. This defaults to running on local vagrant feg VM machines, but can also be pointed to an arbitrary host (e.g. amazon) by specifying a VM. feg_host: The ssh address string of the machine to run the package command. Formatted as "<user>@<host>:<port>". If not specified, defaults to the `feg` vagrant VM. vcs: version control system used, "hg" or "git". force: Bypass local commits or changes check if set to True. """ if not force and pkg.check_commit_changes(): abort("Local changes or commits not allowed") if feg_host: env.host_string = feg_host (env.user, _, _) = split_hoststring(feg_host) else: setup_env_vagrant("feg") target = "/tmp/magmadeploy_feg" run("rm -rf %s" % target) run("mkdir -p %s" % target) _package_python(target) _package_go(target) _package_scripts(target) return _push_archive_to_s3(vcs, target)
def package(vcs='hg', all_deps="False"): """ Builds the magma package """ all_deps = False if all_deps == "False" else True # If a host list isn't specified, default to the magma vagrant vm if not env.hosts: setup_env_vagrant() if not hasattr(env, 'debug_mode'): print("Error: The Deploy target isn't specified. Specify one with\n\n" "\tfab [dev|test] package") exit(1) hash = pkg.get_commit_hash(vcs) with cd('~/magma/lte/gateway'): print("Building magma package, picking up commit %s..." % hash) run('make clean') build_type = "Debug" if env.debug_mode else "RelWithDebInfo" run('./release/build-magma.sh -h %s -t %s' % (hash, build_type)) # Generate magma dependency packages print("Generating magma dependency packages") with cd('python'): run('../release/pydep finddep -b ../python/setup.py') run('mv *.deb ../') run('rm -rf ~/magma-packages') run('mkdir -p ~/magma-packages') run('mv *.deb ~/magma-packages') if all_deps: pkg.download_all_pkgs() run('cp /var/cache/apt/archives/*.deb ~/magma-packages') pkg.upload_pkgs_to_aws()
def connect_gateway_to_cloud(control_proxy_setting_path=None, cert_path=DEFAULT_CERT): """ Setup the gateway VM to connects to the cloud Path to control_proxy.yml and rootCA.pem could be specified to use non-default control proxy setting and certificates """ setup_env_vagrant() dev_utils.connect_gateway_to_cloud(control_proxy_setting_path, cert_path)
def vagrant_setup(host, destroy_vm): """ Setup the specified vagrant box host: the Vagrant box to setup, e.g. "magma" """ if destroy_vm: vagrant.teardown_vagrant(host) vagrant.setup_env_vagrant(host) return env.hosts[0]
def _setup_cloud_environment(control_proxy_path): setup_env_vagrant() # Add the override for the production endpoints run("sudo rm -rf /var/opt/magma/configs") run("sudo mkdir /var/opt/magma/configs") if control_proxy_path is not None: run("sudo cp " + control_proxy_path + " /var/opt/magma/configs/control_proxy.yml") # Use the prod rootCA cert run("sudo rm -rf /var/opt/magma/certs") run("sudo mkdir /var/opt/magma/certs") run("sudo cp magma/.cache/test_certs/rootCA.pem /var/opt/magma/certs/") # Restart the bootstrapper in the gateway to get the new certs run("sudo systemctl stop magma@*") run("sudo systemctl restart magma@magmad")
def connect_gateway_to_cloud(control_proxy_setting_path=None, cert_path=DEFAULT_CERT): """ Setup the gateway VM to connects to the cloud Path to control_proxy.yml and rootCA.pem could be specified to use non-default control proxy setting and certificates """ setup_env_vagrant() # Add the override for the production endpoints run("sudo rm -rf /var/opt/magma/configs") run("sudo mkdir /var/opt/magma/configs") if control_proxy_setting_path is not None: run("sudo cp " + control_proxy_setting_path + " /var/opt/magma/configs/control_proxy.yml") # Copy certs which will be used by the bootstrapper run("sudo rm -rf /var/opt/magma/certs") run("sudo mkdir /var/opt/magma/certs") run("sudo cp " + cert_path + " /var/opt/magma/certs/") # Restart the bootstrapper in the gateway to use the new certs run("sudo systemctl stop magma@*") run("sudo systemctl restart magma@magmad")
def get_test_logs(gateway_host=None, test_host=None, trf_host=None): ''' Downloads the relevant magma logs from the given gateway and test machines. Places the logs in /tmp/build_logs.zip gateway_host: The ssh address string of the gateway machine formatted as "host:port". If not specified, defaults to the `magma` vagrant box. test_host: The ssh address string of the test machine formatted as "host:port". If not specified, defaults to the `magma_test` vagrant box. trf_host: The ssh address string of the machine to run the TrafficServer on. Formatted as "host:port". If not specified, defaults to the `magma_trfserver` vagrant box. ''' # Grab the build logs from the machines and bring them to the host local('rm -rf /tmp/build_logs') local('mkdir /tmp/build_logs') local('mkdir /tmp/build_logs/dev') local('mkdir /tmp/build_logs/test') local('mkdir /tmp/build_logs/trfserver') dev_files = ['/var/log/mme.log', '/var/log/syslog'] test_files = ['/var/log/syslog', '/tmp/fw/'] trf_files = ['/home/admin/nohup.out'] # Set up to enter the gateway host env.host_string = gateway_host if not gateway_host: setup_env_vagrant("magma") gateway_host = env.hosts[0] (env.user, _, _) = split_hoststring(gateway_host) # Don't fail if the logs don't exists for p in dev_files: with settings(warn_only=True): get(remote_path=p, local_path='/tmp/build_logs/dev/', use_sudo=True) # Set up to enter the trfserver host env.host_string = trf_host if not trf_host: setup_env_vagrant("magma_trfserver") trf_host = env.hosts[0] (env.user, _, _) = split_hoststring(trf_host) # Don't fail if the logs don't exists for p in trf_files: with settings(warn_only=True): get(remote_path=p, local_path='/tmp/build_logs/trfserver/', use_sudo=True) # Set up to enter the test host env.host_string = test_host if not test_host: setup_env_vagrant("magma_test") test_host = env.hosts[0] (env.user, _, _) = split_hoststring(test_host) # Fix the permissions on the fw directory -- it has permissions 000 # otherwise with settings(warn_only=True): run('sudo chmod 755 /tmp/fw') # Don't fail if the logs don't exists for p in test_files: with settings(warn_only=True): get(remote_path=p, local_path='/tmp/build_logs/test/', use_sudo=True) local('rm -rf /tmp/build_logs.zip') local('zip -r /tmp/build_logs.zip /tmp/build_logs') local('rm -rf /tmp/build_logs')
def integ_test(gateway_host=None, test_host=None, trf_host=None, destroy_vm="True"): """ Run the integration tests. This defaults to running on local vagrant machines, but can also be pointed to an arbitrary host (e.g. amazon) by passing "address:port" as arguments gateway_host: The ssh address string of the machine to run the gateway services on. Formatted as "host:port". If not specified, defaults to the `magma` vagrant box. test_host: The ssh address string of the machine to run the tests on on. Formatted as "host:port". If not specified, defaults to the `magma_test` vagrant box. trf_host: The ssh address string of the machine to run the TrafficServer on. Formatted as "host:port". If not specified, defaults to the `magma_trfserver` vagrant box. """ destroy_vm = bool(strtobool(destroy_vm)) # Setup the gateway: use the provided gateway if given, else default to the # vagrant machine gateway_ip = '192.168.60.142' if not gateway_host: gateway_host = vagrant_setup("magma", destroy_vm) else: ansible_setup(gateway_host, "dev", "magma_dev.yml") gateway_ip = gateway_host.split('@')[1].split(':')[0] execute(_dist_upgrade) execute(_build_magma) execute(_run_unit_tests) execute(_python_coverage) execute(_start_gateway) # Run suite of integ tests that are required to be run on the access gateway # instead of the test VM # TODO: fix the integration test T38069907 # execute(_run_local_integ_tests) # Setup the trfserver: use the provided trfserver if given, else default to the # vagrant machine if not trf_host: trf_host = vagrant_setup("magma_trfserver", destroy_vm) else: ansible_setup(trf_host, "trfserver", "magma_trfserver.yml") execute(_start_trfserver) # Run the tests: use the provided test machine if given, else default to # the vagrant machine if not test_host: test_host = vagrant_setup("magma_test", destroy_vm) else: ansible_setup(test_host, "test", "magma_test.yml") execute(_make_integ_tests) execute(_run_integ_tests, gateway_ip) if not gateway_host: setup_env_vagrant() else: env.hosts = [gateway_host] execute(_oai_coverage)
def upload_to_aws(): # If a host list isn't specified, default to the magma vagrant vm if not env.hosts: setup_env_vagrant() pkg.upload_pkgs_to_aws()