delete registry docker repo on target node

this action executes after uninstalling openstack

Change-Id: Ie4264bf671968e239643554d9e4d96a461cec811
This commit is contained in:
zhouya 2017-05-03 16:28:55 +08:00
parent 0cf10bf1da
commit df0679ee00
5 changed files with 116 additions and 45 deletions

View File

@ -985,11 +985,11 @@ def check_vlan_nic_and_join_vlan_network(req, cluster_id,
# physical nic name. # physical nic name.
vlan_id = nic_name_list[len(nic_name_list) - 1] vlan_id = nic_name_list[len(nic_name_list) - 1]
nic_name = interface_info['name'][: -len(vlan_id) - 1] nic_name = interface_info['name'][: -len(vlan_id) - 1]
exclude_networks = ['DATAPLANE', 'EXTERNAL'] exclude_networks = ['EXTERNAL']
use_share_disk = if_used_shared_storage(req, cluster_id) use_share_disk = if_used_shared_storage(req, cluster_id)
if not use_share_disk: if not use_share_disk:
exclude_networks.append('STORAGE') #exclude_networks.append('STORAGE')
pass
for network in networks: for network in networks:
if network['network_type'] in exclude_networks: if network['network_type'] in exclude_networks:
continue continue
@ -1070,11 +1070,12 @@ def check_bond_or_ether_nic_and_join_network(req,
% host_info_ip % host_info_ip
LOG.error(msg) LOG.error(msg)
raise exception.Forbidden(msg) raise exception.Forbidden(msg)
exclude_networks = ['DATAPLANE', 'EXTERNAL'] exclude_networks = ['EXTERNAL']
use_share_disk = if_used_shared_storage(req, use_share_disk = if_used_shared_storage(req,
cluster_id) cluster_id)
if not use_share_disk: if not use_share_disk:
exclude_networks.append('STORAGE') #exclude_networks.append('STORAGE')
pass
for network in networks: for network in networks:
if network['network_type'] in exclude_networks: if network['network_type'] in exclude_networks:
continue continue

View File

@ -25,6 +25,7 @@ import daisy.api.backends.common as daisy_cmn
import daisy.api.backends.kolla.common as kolla_cmn import daisy.api.backends.kolla.common as kolla_cmn
import daisy.registry.client.v1.api as registry import daisy.registry.client.v1.api as registry
from threading import Thread from threading import Thread
import threading
from daisy.common import exception from daisy.common import exception
@ -35,6 +36,7 @@ _LI = i18n._LI
_LW = i18n._LW _LW = i18n._LW
kolla_state = kolla_cmn.KOLLA_STATE kolla_state = kolla_cmn.KOLLA_STATE
thread_flag = {}
def update_all_host_progress_to_db(req, hosts_id_list, role_host_meta={}): def update_all_host_progress_to_db(req, hosts_id_list, role_host_meta={}):
@ -94,6 +96,46 @@ def _calc_uninstall_progress(log_file):
return progress return progress
def remove_registry(req, hosts_id_list, host_ip, log_file):
LOG.info(_("begin to remove docker images on host %s" % host_ip))
try:
check_docker_container_cmd = \
"ssh -o StrictHostKeyChecking=no %s \
docker ps |grep registry:2 |awk -F ' ' '{print $2}'" % (host_ip)
docker_container_result = \
subprocess.check_output(check_docker_container_cmd,
shell=True,
stderr=subprocess.STDOUT)
stop_docker_container_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker stop registry"' % (host_ip)
remove_docker_container_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker rm registry"' % (host_ip)
remove_docker_images_cmd = \
'ssh -o StrictHostKeyChecking=no %s \
"docker rmi -f registry:2"' % (host_ip)
if "registry:2" in docker_container_result:
daisy_cmn.subprocess_call(stop_docker_container_cmd, log_file)
daisy_cmn.subprocess_call(remove_docker_container_cmd, log_file)
daisy_cmn.subprocess_call(remove_docker_images_cmd, log_file)
except Exception as e:
message = "remove docker images failed on host %s!" % host_ip
LOG.error(message)
thread_flag['flag'] = False
update_all_host_progress_to_db(req, hosts_id_list,
{'progress': 90,
'status': kolla_state[
'UNINSTALL_FAILED'],
'messages': message})
raise exception.UninstallException(message)
else:
LOG.info(_("remove docker images on host %s successfully!" % host_ip))
class KOLLAUninstallTask(Thread): class KOLLAUninstallTask(Thread):
""" """
Class for kolla uninstall openstack. Class for kolla uninstall openstack.
@ -180,32 +222,55 @@ class KOLLAUninstallTask(Thread):
update_all_host_progress_to_db( update_all_host_progress_to_db(
self.req, hosts_id_list, self.req, hosts_id_list,
{'progress': self.progress, {'progress': self.progress,
'status': kolla_state[ 'status': kolla_state['UNINSTALLING'],
'UNINSTALLING'],
'messages': self.message}) 'messages': self.message})
execute_times += 1 execute_times += 1
if self.progress == 90: if self.progress == 90:
LOG.info(_("openstack uninstall successfully")) threads = []
self.message = "openstack uninstall successfully" for host_ip in hosts_ip_set:
update_all_host_progress_to_db(self.req, hosts_id_list, t = threading.Thread(target=remove_registry,
{'progress': 100, args=(self.req, hosts_id_list,
'status': kolla_state[ host_ip, fp))
'INIT'], t.setDaemon(True)
'messages': self.message}) t.start()
for host_id in hosts_id_list: threads.append(t)
daisy_cmn.update_db_host_status( try:
self.req, host_id, {'tecs_version_id': '', LOG.info(_("remove registry uninstall threads "
'tecs_patch_id': ''}) "have started, please waiting...."))
for t in threads:
t.join()
except:
LOG.error("join remove registry uninstall "
"thread %s failed!" % t)
cluster_meta = {} if thread_flag.get('flag', None) is not None and \
cluster_meta['tecs_version_id'] = '' thread_flag['flag'] == False:
cluster_meta = registry.update_cluster_metadata( self.message = "remove registry uninstall "\
self.req.context, self.cluster_id, cluster_meta) " threads failed!"
LOG.error(self.message)
raise exception.UninstallException(self.message)
else:
LOG.info(_("openstack uninstall successfully"))
self.message = "openstack uninstall successfully"
update_all_host_progress_to_db(
self.req, hosts_id_list,
{'progress': 100,
'status': kolla_state['INIT'],
'messages': self.message})
for host_id in hosts_id_list:
daisy_cmn.update_db_host_status(
self.req, host_id, {'tecs_version_id': '',
'tecs_patch_id': ''})
LOG.info(_("openstack uninstalled for " cluster_meta = {}
"cluster %s successfully." cluster_meta['tecs_version_id'] = ''
% self.cluster_id)) cluster_meta = registry.update_cluster_metadata(
self.req.context, self.cluster_id, cluster_meta)
LOG.info(_("openstack uninstalled for "
"cluster %s successfully."
% self.cluster_id))
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
LOG.error("kolla-ansible destory failed!") LOG.error("kolla-ansible destory failed!")

View File

@ -177,10 +177,10 @@ class DaisyCinderVolumeTest(base.BaseDaisyTest):
'af47d81c-7ae4-4148-a801-b4a5c6a52074' 'af47d81c-7ae4-4148-a801-b4a5c6a52074'
self.assertRaisesMessage(client_exc.HTTPNotFound, self.assertRaisesMessage(client_exc.HTTPNotFound,
"404 Not Found: The resource could not be " "404 Not Found\nThe resource could not be "
"found.: Role with identifier " "found.\n Role with identifier "
"af47d81c-7ae4-4148-a801-b4a5c6a52074 not " "af47d81c-7ae4-4148-a801-b4a5c6a52074 not "
"found (HTTP 404)", "found (HTTP 404)",
self.add_cinder_volume, self.add_cinder_volume,
**self.cinder_volume_add_meta) **self.cinder_volume_add_meta)
del self.cinder_volume_add_meta['role_id'] del self.cinder_volume_add_meta['role_id']
@ -195,8 +195,8 @@ class DaisyCinderVolumeTest(base.BaseDaisyTest):
'test_driver' 'test_driver'
self.assertRaisesMessage(client_exc.HTTPBadRequest, self.assertRaisesMessage(client_exc.HTTPBadRequest,
"400 Bad Request: volume_driver test_driver " "400 Bad Request\nvolume_driver test_driver "
"is not supported (HTTP 400)", "is not supported\n (HTTP 400)",
self.add_cinder_volume, self.add_cinder_volume,
**self.cinder_volume_add_meta) **self.cinder_volume_add_meta)
del self.cinder_volume_add_meta['role_id'] del self.cinder_volume_add_meta['role_id']
@ -264,8 +264,8 @@ class DaisyCinderVolumeTest(base.BaseDaisyTest):
update_meta = {'volume_driver': 'test_driver'} update_meta = {'volume_driver': 'test_driver'}
self.assertRaisesMessage( self.assertRaisesMessage(
client_exc.HTTPBadRequest, client_exc.HTTPBadRequest,
"400 Bad Request: volume_driver test_driver is not supported" "400 Bad Request\nvolume_driver test_driver is not supported\n"
" (HTTP 400)", " (HTTP 400)",
self.update_cinder_volume, cinder_volume_info.id, **update_meta) self.update_cinder_volume, cinder_volume_info.id, **update_meta)
self.delete_cinder_volume(cinder_volume_info.id) self.delete_cinder_volume(cinder_volume_info.id)

View File

@ -96,8 +96,8 @@ class TecsLogicalNetworkTest(base.BaseDaisyTest):
self.assertRaisesMessage( self.assertRaisesMessage(
client_exc.HTTPBadRequest, client_exc.HTTPBadRequest,
"400 Bad Request: " "400 Bad Request\n"
"Logic_network flat1 is not valid range. (HTTP 400)", "Logic_network flat1 is not valid range.\n (HTTP 400)",
self.add_cluster, **fake_cluster) self.add_cluster, **fake_cluster)
# STC-F-Daisy_Logical_Network-0002 # STC-F-Daisy_Logical_Network-0002
@ -148,8 +148,8 @@ class TecsLogicalNetworkTest(base.BaseDaisyTest):
'routers': fake_router}) 'routers': fake_router})
self.assertRaisesMessage( self.assertRaisesMessage(
client_exc.HTTPBadRequest, client_exc.HTTPBadRequest,
"400 Bad Request: Logic network's subnets is all related " "400 Bad Request\nLogic network's subnets is all related "
"with a router, it's not allowed. (HTTP 400)", "with a router, it's not allowed.\n (HTTP 400)",
self.add_cluster, **fake_cluster) self.add_cluster, **fake_cluster)
tmp_fake_router1 = copy.deepcopy(fake_router) tmp_fake_router1 = copy.deepcopy(fake_router)
@ -157,8 +157,8 @@ class TecsLogicalNetworkTest(base.BaseDaisyTest):
fake_cluster.update({'routers': tmp_fake_router1}) fake_cluster.update({'routers': tmp_fake_router1})
self.assertRaisesMessage( self.assertRaisesMessage(
client_exc.HTTPBadRequest, client_exc.HTTPBadRequest,
"400 Bad Request: Logic network's subnets is all related with a " "400 Bad Request\nLogic network's subnets is all related with a "
"router, it's not allowed. (HTTP 400)", "router, it's not allowed.\n (HTTP 400)",
self.add_cluster, **fake_cluster) self.add_cluster, **fake_cluster)
tmp_fake_router2 = copy.deepcopy(fake_router) tmp_fake_router2 = copy.deepcopy(fake_router)
@ -166,8 +166,8 @@ class TecsLogicalNetworkTest(base.BaseDaisyTest):
fake_cluster.update({'routers': tmp_fake_router2}) fake_cluster.update({'routers': tmp_fake_router2})
self.assertRaisesMessage( self.assertRaisesMessage(
client_exc.HTTPBadRequest, client_exc.HTTPBadRequest,
"400 Bad Request: " "400 Bad Request\n"
"Logic_network test is not valid range. (HTTP 400)", "Logic_network test is not valid range.\n (HTTP 400)",
self.add_cluster, **fake_cluster) self.add_cluster, **fake_cluster)
tmp_fake_router3 = copy.deepcopy(fake_router) tmp_fake_router3 = copy.deepcopy(fake_router)
@ -175,7 +175,7 @@ class TecsLogicalNetworkTest(base.BaseDaisyTest):
fake_cluster.update({'routers': tmp_fake_router3}) fake_cluster.update({'routers': tmp_fake_router3})
self.assertRaisesMessage( self.assertRaisesMessage(
client_exc.HTTPBadRequest, client_exc.HTTPBadRequest,
"400 Bad Request: Subnet test is not valid range. (HTTP 400)", "400 Bad Request\nSubnet test is not valid range.\n (HTTP 400)",
self.add_cluster, **fake_cluster) self.add_cluster, **fake_cluster)
self.private_network_delete() self.private_network_delete()
@ -194,8 +194,8 @@ class TecsLogicalNetworkTest(base.BaseDaisyTest):
'logic_networks': tmp_fake_logical1}) 'logic_networks': tmp_fake_logical1})
self.assertRaisesMessage( self.assertRaisesMessage(
client_exc.HTTPBadRequest, client_exc.HTTPBadRequest,
"400 Bad Request: " "400 Bad Request\n"
"Between floating ip range can not be overlap. (HTTP 400)", "Between floating ip range can not be overlap.\n (HTTP 400)",
self.add_cluster, **fake_cluster) self.add_cluster, **fake_cluster)
tmp_fake_logical2 = copy.deepcopy( tmp_fake_logical2 = copy.deepcopy(
@ -208,7 +208,8 @@ class TecsLogicalNetworkTest(base.BaseDaisyTest):
fake_cluster.update({'logic_networks': tmp_fake_logical2}) fake_cluster.update({'logic_networks': tmp_fake_logical2})
self.assertRaisesMessage( self.assertRaisesMessage(
client_exc.HTTPBadRequest, client_exc.HTTPBadRequest,
"400 Bad Request: Subnet name segment is repetition. (HTTP 400)", "400 Bad Request\nSubnet name segment is repetition.\n "
"(HTTP 400)",
self.add_cluster, **fake_cluster) self.add_cluster, **fake_cluster)
self.private_network_delete() self.private_network_delete()

View File

@ -41,4 +41,8 @@ yum -y install \
python-lesscpy \ python-lesscpy \
python-migrate \ python-migrate \
python-pint \ python-pint \
python-routes python-routes \
gcc \
autoconf \
automake \
glibc-devel