def sync_glance_images(source_env_id, seed_env_id, seed_swift_ep): """Sync glance images from original ENV to seed ENV Args: source_env_id (int): ID of original ENV. seed_env_id (int): ID of seed ENV. seed_swift_ep (str): endpoint's name where swift-proxy service is listening on. Examples: sync_glance_images(2, 3, 'br-mgmt') """ # set glance username glance_user = "******" # set swift container value container = "glance" # choose tenant tenant = "services" # get clusters by id source_env = environment_obj.Environment(source_env_id) seed_env = environment_obj.Environment(seed_env_id) # gather cics admin IPs source_node = next(env_util.get_controllers(source_env)) seed_node = next(env_util.get_controllers(seed_env)) # get cics yaml files source_yaml = env_util.get_astute_yaml(source_env, source_node) seed_yaml = env_util.get_astute_yaml(seed_env, seed_node) # get glance passwords source_glance_pass = get_glance_password(source_yaml) seed_glance_pass = get_glance_password(seed_yaml) # get seed node swift ip seed_swift_ip = get_endpoint_ip(seed_swift_ep, seed_yaml) # get service tenant id & lists of objects for source env source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass) source_swift_list = set( get_swift_objects(source_node, tenant, glance_user, source_glance_pass, source_token, container)) # get service tenant id & lists of objects for seed env seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass) seed_swift_list = set( get_swift_objects(seed_node, tenant, glance_user, seed_glance_pass, seed_token, container)) # get service tenant for seed env seed_tenant = env_util.get_service_tenant_id(seed_env) # check consistency of matched images source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass) seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass) for image in source_swift_list & seed_swift_list: source_obj_etag = get_object_property(source_node, tenant, glance_user, source_glance_pass, source_token, container, image, 'ETag') seed_obj_etag = get_object_property(seed_node, tenant, glance_user, seed_glance_pass, seed_token, container, image, 'ETag') if source_obj_etag != seed_obj_etag: # image should be resynced delete_image(seed_node, tenant, glance_user, seed_glance_pass, seed_token, container, image) LOG.info("Swift %s image should be resynced" % image) seed_swift_list.remove(image) # migrate new images for image in source_swift_list - seed_swift_list: # download image on source's node local drive source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass) download_image(source_node, tenant, glance_user, source_glance_pass, source_token, container, image) # transfer image source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass) seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass) transfer_image(source_node, tenant, glance_user, seed_glance_pass, seed_token, container, image, seed_swift_ip, seed_tenant) # remove transferred image ssh.sftp(source_node).remove(image) # delete outdated images for image in seed_swift_list - source_swift_list: token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass) delete_image(seed_node, tenant, glance_user, seed_glance_pass, token, container, image)
def test_get_service_tenant_id(mocker, node): mock_obj = mocker.patch("octane.util.env.get_openstack_project_value") env = mock.Mock() env_util.get_service_tenant_id(env, node) mock_obj.assert_called_once_with(env, node, "services")
def preupgrade(self): self.service_tenant_id = env_util.get_service_tenant_id( self.env, self.node)
def sync_glance_images(source_env_id, seed_env_id, seed_swift_ep): """Sync glance images from original ENV to seed ENV Args: source_env_id (int): ID of original ENV. seed_env_id (int): ID of seed ENV. seed_swift_ep (str): endpoint's name where swift-proxy service is listening on. Examples: sync_glance_images(2, 3, 'br-mgmt') """ # set glance username glance_user = "******" # set swift container value container = "glance" # choose tenant tenant = "services" # get clusters by id source_env = environment_obj.Environment(source_env_id) seed_env = environment_obj.Environment(seed_env_id) # gather cics admin IPs source_node = next(env_util.get_controllers(source_env)) seed_node = next(env_util.get_controllers(seed_env)) # get cics yaml files source_yaml = env_util.get_astute_yaml(source_env, source_node) seed_yaml = env_util.get_astute_yaml(seed_env, seed_node) # get glance passwords source_glance_pass = get_glance_password(source_yaml) seed_glance_pass = get_glance_password(seed_yaml) # get seed node swift ip seed_swift_ip = get_endpoint_ip(seed_swift_ep, seed_yaml) # get service tenant id & lists of objects for source env source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass) source_swift_list = set( get_swift_objects(source_node, tenant, glance_user, source_glance_pass, source_token, container) ) # get service tenant id & lists of objects for seed env seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass) seed_swift_list = set(get_swift_objects(seed_node, tenant, glance_user, seed_glance_pass, seed_token, container)) # get service tenant for seed env seed_tenant = env_util.get_service_tenant_id(seed_env) # check consistency of matched images source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass) seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass) for image in source_swift_list & seed_swift_list: source_obj_etag = get_object_property( source_node, tenant, glance_user, source_glance_pass, source_token, container, image, "ETag" ) seed_obj_etag = get_object_property( seed_node, tenant, glance_user, seed_glance_pass, seed_token, container, image, "ETag" ) if source_obj_etag != seed_obj_etag: # image should be resynced delete_image(seed_node, tenant, glance_user, seed_glance_pass, seed_token, container, image) LOG.info("Swift %s image should be resynced" % image) seed_swift_list.remove(image) # migrate new images for image in source_swift_list - seed_swift_list: # download image on source's node local drive source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass) download_image(source_node, tenant, glance_user, source_glance_pass, source_token, container, image) # transfer image source_token = get_auth_token(source_node, tenant, glance_user, source_glance_pass) seed_token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass) transfer_image( source_node, tenant, glance_user, seed_glance_pass, seed_token, container, image, seed_swift_ip, seed_tenant ) # remove transferred image ssh.sftp(source_node).remove(image) # delete outdated images for image in seed_swift_list - source_swift_list: token = get_auth_token(seed_node, tenant, glance_user, seed_glance_pass) delete_image(seed_node, tenant, glance_user, seed_glance_pass, token, container, image)