Merge "Remove code related to subcloud restore CLI"
This commit is contained in:
commit
5538c9b338
|
@ -90,21 +90,6 @@ class subcloud_manager(base.ResourceManager):
|
|||
resource.append(self.json_to_resource(json_object))
|
||||
return resource
|
||||
|
||||
def subcloud_restore(self, url, body, data):
|
||||
fields = dict()
|
||||
for k, v in body.items():
|
||||
fields.update({k: (v, open(v, 'rb'),)})
|
||||
fields.update(data)
|
||||
enc = MultipartEncoder(fields=fields)
|
||||
headers = {'content-type': enc.content_type}
|
||||
resp = self.http_client.patch(url, enc, headers=headers)
|
||||
if resp.status_code != 200:
|
||||
self._raise_api_exception(resp)
|
||||
json_object = get_json(resp)
|
||||
resource = list()
|
||||
resource.append(self.json_to_resource(json_object))
|
||||
return resource
|
||||
|
||||
def _subcloud_prestage(self, url, data):
|
||||
data = json.dumps(data)
|
||||
resp = self.http_client.patch(url, data)
|
||||
|
@ -179,9 +164,3 @@ class subcloud_manager(base.ResourceManager):
|
|||
data = kwargs.get('data')
|
||||
url = '/subclouds/%s/reinstall' % subcloud_ref
|
||||
return self.subcloud_reinstall(url, files, data)
|
||||
|
||||
def restore_subcloud(self, subcloud_ref, **kwargs):
|
||||
files = kwargs.get('files')
|
||||
data = kwargs.get('data')
|
||||
url = '/subclouds/%s/restore' % subcloud_ref
|
||||
return self.subcloud_restore(url, files, data)
|
||||
|
|
|
@ -644,7 +644,7 @@ class RestoreSubcloud(base.DCManagerShowOne):
|
|||
|
||||
parser.add_argument(
|
||||
'--restore-values',
|
||||
required=True,
|
||||
required=False,
|
||||
help='YAML file containing subcloud restore settings. '
|
||||
'Can be either a local file path or a URL.'
|
||||
)
|
||||
|
@ -672,49 +672,9 @@ class RestoreSubcloud(base.DCManagerShowOne):
|
|||
return parser
|
||||
|
||||
def _get_resources(self, parsed_args):
|
||||
subcloud_ref = parsed_args.subcloud
|
||||
dcmanager_client = self.app.client_manager.subcloud_manager
|
||||
files = dict()
|
||||
data = dict()
|
||||
|
||||
if parsed_args.with_install:
|
||||
data['with_install'] = 'true'
|
||||
|
||||
# Get the restore values yaml file
|
||||
if not os.path.isfile(parsed_args.restore_values):
|
||||
error_msg = "restore-values does not exist: %s" % \
|
||||
parsed_args.restore_values
|
||||
raise exceptions.DCManagerClientException(error_msg)
|
||||
files['restore_values'] = parsed_args.restore_values
|
||||
|
||||
# Prompt the user for the subcloud's password if it isn't provided
|
||||
if parsed_args.sysadmin_password is not None:
|
||||
data['sysadmin_password'] = base64.b64encode(
|
||||
parsed_args.sysadmin_password.encode("utf-8"))
|
||||
else:
|
||||
password = utils.prompt_for_password()
|
||||
data["sysadmin_password"] = base64.b64encode(
|
||||
password.encode("utf-8"))
|
||||
|
||||
subcloud_list = \
|
||||
dcmanager_client.subcloud_manager.subcloud_detail(subcloud_ref)
|
||||
if subcloud_list:
|
||||
if subcloud_list[0].management_state != 'unmanaged':
|
||||
error_msg = "Subcloud can not be restored while it is " +\
|
||||
"still in managed state. Please unmanage " +\
|
||||
"the subcloud and try again."
|
||||
raise exceptions.DCManagerClientException(error_msg)
|
||||
else:
|
||||
error_msg = subcloud_ref + " not found."
|
||||
raise exceptions.DCManagerClientException(error_msg)
|
||||
|
||||
try:
|
||||
return dcmanager_client.subcloud_manager.restore_subcloud(
|
||||
subcloud_ref, files=files, data=data)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
error_msg = "Unable to restore subcloud %s" % (subcloud_ref)
|
||||
raise exceptions.DCManagerClientException(error_msg)
|
||||
deprecation_msg = ('This command has been deprecated. Please use '
|
||||
'subcloud-backup restore instead.')
|
||||
raise exceptions.DCManagerClientException(deprecation_msg)
|
||||
|
||||
|
||||
class PrestageSubcloud(base.DCManagerShowOne):
|
||||
|
|
|
@ -427,60 +427,17 @@ class TestCLISubcloudManagerV1(base.BaseCommandTest):
|
|||
|
||||
@mock.patch('getpass.getpass', return_value='testpassword')
|
||||
def test_restore_subcloud(self, getpass):
|
||||
self.client.subcloud_manager.subcloud_detail.\
|
||||
return_value = [SUBCLOUD]
|
||||
|
||||
SUBCLOUD_BEING_RESTORED = copy.copy(SUBCLOUD)
|
||||
setattr(SUBCLOUD_BEING_RESTORED,
|
||||
'deploy_status',
|
||||
DEPLOY_STATE_PRE_RESTORE)
|
||||
|
||||
self.client.subcloud_manager.restore_subcloud.\
|
||||
return_value = [SUBCLOUD_BEING_RESTORED]
|
||||
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
file_path = os.path.abspath(f.name)
|
||||
actual_call = self.call(
|
||||
subcloud_cmd.RestoreSubcloud,
|
||||
app_args=[ID,
|
||||
'--restore-values', file_path])
|
||||
self.assertEqual((ID, NAME,
|
||||
DESCRIPTION, LOCATION,
|
||||
SOFTWARE_VERSION, MANAGEMENT_STATE,
|
||||
AVAILABILITY_STATUS, DEPLOY_STATE_PRE_RESTORE,
|
||||
MANAGEMENT_SUBNET, MANAGEMENT_START_IP,
|
||||
MANAGEMENT_END_IP, MANAGEMENT_GATEWAY_IP,
|
||||
SYSTEMCONTROLLER_GATEWAY_IP,
|
||||
DEFAULT_SUBCLOUD_GROUP_ID,
|
||||
TIME_NOW, TIME_NOW, BACKUP_STATUS, BACKUP_DATETIME
|
||||
), actual_call[1])
|
||||
|
||||
@mock.patch('getpass.getpass', return_value='testpassword')
|
||||
def test_restore_file_does_not_exist(self, getpass):
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
file_path = os.path.abspath(f.name)
|
||||
|
||||
e = self.assertRaises(DCManagerClientException,
|
||||
self.call,
|
||||
subcloud_cmd.RestoreSubcloud,
|
||||
app_args=[ID, '--restore-values', file_path])
|
||||
self.assertTrue('restore-values does not exist'
|
||||
in str(e))
|
||||
e = self.assertRaises(DCManagerClientException,
|
||||
self.call,
|
||||
subcloud_cmd.RestoreSubcloud,
|
||||
app_args=[ID, '--restore-values', file_path])
|
||||
|
||||
@mock.patch('getpass.getpass', return_value='testpassword')
|
||||
def test_restore_subcloud_does_not_exist(self, getpass):
|
||||
self.client.subcloud_manager.subcloud_detail.\
|
||||
return_value = []
|
||||
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
file_path = os.path.abspath(f.name)
|
||||
|
||||
e = self.assertRaises(DCManagerClientException,
|
||||
self.call,
|
||||
subcloud_cmd.RestoreSubcloud,
|
||||
app_args=[ID, '--restore-values', file_path])
|
||||
self.assertTrue('does not exist'
|
||||
in str(e))
|
||||
deprecation_msg = ('This command has been deprecated. Please use '
|
||||
'subcloud-backup restore instead.')
|
||||
self.assertTrue(deprecation_msg in str(e))
|
||||
|
||||
def test_prestage_with_subcloudID(self):
|
||||
self.client.subcloud_manager.prestage_subcloud.\
|
||||
|
|
Loading…
Reference in New Issue