def cleanup_environment(env_id): env = objects.Environment(env_id) nodes = env.get_all_nodes() for node in nodes: node_util.remove_compute_upgrade_levels(node) controller = env_util.get_one_controller(env) sftp = ssh.sftp(controller) admin_pass = env_util.get_admin_password(env, controller) script_filename = 'clean_env.py' with ssh.tempdir(controller) as tempdir: script_src_filename = os.path.join(magic_consts.CWD, "helpers", script_filename) script_dst_filename = os.path.join(tempdir, script_filename) sftp.put(script_src_filename, script_dst_filename) command = [ 'sh', '-c', '. /root/openrc; export OS_PASSWORD={0}; python {1}'.format( admin_pass, script_dst_filename), ] with ssh.popen(command, node=controller, stdin=ssh.PIPE) as proc: roles = ["controller", "compute"] for node in env_util.get_nodes(env, roles): data = "{0}\n{1}\n".format(node.data['fqdn'].split('.')[0], node.data['fqdn']) proc.stdin.write(data)
def create(env_id, ip_addr, network, vip_name, vip_namespace=None): env = objects.Environment(env_id) vip_data = { 'ip_addr': ip_addr, 'network': network, 'vip_name': vip_name } if vip_namespace is not None: vip_data['vip_namespace'] = vip_namespace env.create_vip(**vip_data)
def download(env_id, ip_addr_id=None, network_id=None, network_role=None, file_path=None): env = objects.Environment(env_id) vips_data = env.get_vips_data(ip_address_id=ip_addr_id, network=network_id, network_role=network_role) vips_data_file_path = env.write_vips_data_to_file( vips_data, file_path=file_path, serializer=Serializer()) return vips_data_file_path
def update_env_networks(env_id, networks): fields_to_update = ['meta', 'ip_ranges'] env = objects.Environment(env_id) release_id = env.get_fresh_data()['release_id'] network_data = env.get_network_data() node_group_id = None for ng in network_data['networks']: if ng['name'] in KEEP_NETWORK_NAMES: continue if node_group_id is None: # for now we'll have only one node group # so just take it id from any network node_group_id = ng['group_id'] objects.NetworkGroup(ng['id']).delete() data_to_update = {} for ng in networks: if ng['name'] in KEEP_NETWORK_NAMES: continue try: objects.NetworkGroup.create( ng['name'], release_id, ng['vlan_start'], ng['cidr'], ng['gateway'], node_group_id, ng['meta'] ) except HTTPError: LOG.error("Cannot sync network '{0}'".format(ng['name'])) continue data = {} for key in fields_to_update: data[key] = ng[key] data_to_update[ng['name']] = data # now we need to update new networks with # correct ip_ranges and meta network_data = env.get_network_data() network_data['networks'] = [ng for ng in network_data['networks'] if ng['name'] not in KEEP_NETWORK_NAMES] for ng in network_data['networks']: if ng['name'] in data_to_update: for k in fields_to_update: ng[k] = data_to_update[ng['name']][k] env.set_network_data(network_data)
def get_env_plugins_graphs_list(self, env_id): """Get list of graphs related to plugins active for the given environment. :param env_id: environment ID :type env_id: int :return: list of graphs records :rtype: list[dict] """ env = objects.Environment(env_id) enabled_plugins_ids = env.get_enabled_plugins() result = [] for plugin_id in enabled_plugins_ids: result += self.connection.get_request( self.related_graphs_list_api_path.format( related_model='plugins', related_model_id=plugin_id), params={'fetch_related': '0'}) return result
def start(self, environment_id, ostf_credentials=None, test_sets=None, force=False): """Run test sets for a given environment. If test_sets is None then all test sets will be run :param environment_id: Id of environment :type environment_id: int :param ostf_credentials: ostf credentials :type ostf_credentials: dict :param test_sets: list of test sets :type test_sets: list :param force: :type force: bool :return: running health test sets as a list of dict :rtype: list """ env_obj = objects.Environment(environment_id) if env_obj.status not in self._allowed_statuses and not force: raise error.EnvironmentException( "Environment is not ready to run health check " "because it is in '{0}' state. Health check is likely " "to fail because of this. Use '--force' flag " "to proceed anyway.".format(env_obj.status)) if env_obj.is_customized and not force: raise error.EnvironmentException( "Environment deployment facts were updated. " "Health check is likely to fail because of " "that. Use '--force' flag to proceed anyway.") test_sets_to_run = test_sets or set( ts['id'] for ts in self.get_all(environment_id)) return self._entity_wrapper.run_test_sets(environment_id, test_sets_to_run, ostf_credentials)
def upload(env_id, file_path): env = objects.Environment(env_id) vips_data = env.read_vips_data_from_file(file_path=file_path, serializer=Serializer()) env.set_vips_data(vips_data)
def get_env_networks(env_id): env = objects.Environment(env_id) network_data = env.get_network_data() return network_data['networks']
def take_action(self, parsed_args): orig_env = objects.Environment(parsed_args.original_env) networks = env_util.get_env_networks(orig_env) update_env_networks(parsed_args.seed_env, networks)
def setUp(self): super(TestEnvironmentObject, self).setUp() self.env_object = objects.Environment(1)