Skip to content
Snippets Groups Projects
Commit b14606db authored by claudio's avatar claudio
Browse files

[NRRPLT-6308] Clone a cloned experiment

Change-Id: I9db84f7bcfcf4d0b1707060d28a81b2c9a4bbe4a
parent d8f0b701
No related branches found
No related tags found
No related merge requests found
...@@ -430,6 +430,26 @@ mock-server-5 ...@@ -430,6 +430,26 @@ mock-server-5
self._vc.clone_experiment_to_storage('foo/bar1.xml') self._vc.clone_experiment_to_storage('foo/bar1.xml')
mock_logger.assert_called_once() mock_logger.assert_called_once()
def test_clone_cloned_experiment(self):
self.assertRaises(AssertionError, self._vc.clone_cloned_experiment, 123)
@patch('hbp_nrp_virtual_coach.virtual_coach.VirtualCoach._VirtualCoach__get_experiment_list')
def test_clone_missing_experiment(self, mock_list):
mock_list.return_value = []
self.assertRaises(ValueError, self._vc.clone_cloned_experiment, 'missing_id')
@patch('hbp_nrp_virtual_coach.virtual_coach.VirtualCoach._VirtualCoach__get_experiment_list')
@patch('requests.post')
def test_clone_experiment_to_storage_fail(self, request, mock_list):
mock_list.return_value = ['missing_id']
class Request(object):
status_code = 477
request.return_value = Request()
self._vc._VirtualCoach__storage_username = 'token'
self.assertRaises(Exception, self._vc.clone_cloned_experiment, 'missing_id')
@patch('hbp_nrp_virtual_coach.virtual_coach.VirtualCoach._VirtualCoach__get_experiment_list') @patch('hbp_nrp_virtual_coach.virtual_coach.VirtualCoach._VirtualCoach__get_experiment_list')
def test_print_cloned_experiments_fail(self, mock_list): def test_print_cloned_experiments_fail(self, mock_list):
mock_list.return_value = self._mock_exp_list mock_list.return_value = self._mock_exp_list
......
...@@ -320,6 +320,35 @@ class VirtualCoach(object): ...@@ -320,6 +320,35 @@ class VirtualCoach(object):
else: else:
logger.info('Experiment "%s" cloned successfully', exp_name) logger.info('Experiment "%s" cloned successfully', exp_name)
def clone_cloned_experiment(self, experiment_id):
"""
Attempts to clone a cloned experiment to the Storage Server.
:param experiment_id: The id of the cloned experiment to be cloned. E.g. benchmark_p3dx_1
"""
assert isinstance(experiment_id, str)
exp_list = self.__get_experiment_list(cloned=True)
if experiment_id not in exp_list:
raise ValueError('Experiment id : %s is invalid, please check the list '
'of all Experiments ids:\n%s' % (experiment_id, '\n'.join(exp_list)))
# Raise Error in case no storage server token available. To get the token, the VC has to be
# instantiated with the storage_username parameter
if self.__storage_username is None:
raise ValueError('No Storage Server credentials found.'
'To be able to clone experiments, you have to instantiate the'
'Virtual Coach either with the storage_username parameter or'
'the oidc_username parameter and login successfully')
res = requests.post('%s/%s' % (self.__config['proxy-services']['experiment-clone'],
experiment_id),
headers=self.__storage_headers)
if res.status_code != 200:
raise Exception('Cloning Experiment failed, Status Code: %s' % res.status_code)
else:
logger.info('Experiment "%s" cloned successfully', experiment_id)
def print_cloned_experiments(self): def print_cloned_experiments(self):
""" """
Prints the list of the cloned experiments' names. Only works if the Virtual Coach was Prints the list of the cloned experiments' names. Only works if the Virtual Coach was
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment