From b14606db3428a4ab5760be97c334d3297595b564 Mon Sep 17 00:00:00 2001
From: claudio <claudio.sousa@epfl.ch>
Date: Mon, 26 Mar 2018 13:54:20 +0200
Subject: [PATCH] [NRRPLT-6308] Clone a cloned experiment
Change-Id: I9db84f7bcfcf4d0b1707060d28a81b2c9a4bbe4a
---
.../tests/test_virtual_coach.py | 20 +++++++++++++
.../hbp_nrp_virtual_coach/virtual_coach.py | 29 +++++++++++++++++++
2 files changed, 49 insertions(+)
diff --git a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/tests/test_virtual_coach.py b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/tests/test_virtual_coach.py
index 1eb3d52..88382a4 100644
--- a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/tests/test_virtual_coach.py
+++ b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/tests/test_virtual_coach.py
@@ -430,6 +430,26 @@ mock-server-5
self._vc.clone_experiment_to_storage('foo/bar1.xml')
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')
def test_print_cloned_experiments_fail(self, mock_list):
mock_list.return_value = self._mock_exp_list
diff --git a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/virtual_coach.py b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/virtual_coach.py
index b6b0eb9..51211a2 100644
--- a/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/virtual_coach.py
+++ b/hbp_nrp_virtual_coach/hbp_nrp_virtual_coach/virtual_coach.py
@@ -320,6 +320,35 @@ class VirtualCoach(object):
else:
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):
"""
Prints the list of the cloned experiments' names. Only works if the Virtual Coach was
--
GitLab