summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/opnfv_testapi/resources
diff options
context:
space:
mode:
Diffstat (limited to 'utils/test/testapi/opnfv_testapi/resources')
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py87
-rw-r--r--utils/test/testapi/opnfv_testapi/resources/scenario_models.py6
2 files changed, 92 insertions, 1 deletions
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
index d6918a69b..e9c19a7a4 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_handlers.py
@@ -114,8 +114,21 @@ class ScenarioGURHandler(GenericScenarioHandler):
self._get_one(query={'name': name})
pass
+ @swagger.operation(nickname="updateScenarioName")
def put(self, name):
- pass
+ """
+ @description: update scenario, only rename is supported currently
+ @param body: fields to be updated
+ @type body: L{ScenarioUpdateRequest}
+ @in body: body
+ @rtype: L{Scenario}
+ @return 200: update success
+ @raise 404: scenario not exist
+ @raise 403: nothing to update
+ """
+ query = {'name': name}
+ db_keys = ['name']
+ self._update(query=query, db_keys=db_keys)
@swagger.operation(nickname="deleteScenarioByName")
def delete(self, name):
@@ -150,6 +163,9 @@ class ScenarioUpdater(object):
('versions', 'post'): self._update_requests_add_versions,
('versions', 'put'): self._update_requests_update_versions,
('versions', 'delete'): self._update_requests_delete_versions,
+ ('installers', 'post'): self._update_requests_add_installers,
+ ('installers', 'put'): self._update_requests_update_installers,
+ ('installers', 'delete'): self._update_requests_delete_installers,
}
updates[(item, action)](self.data)
@@ -250,6 +266,19 @@ class ScenarioUpdater(object):
def _update_requests_delete_versions(self, installer):
installer.versions = self._remove_versions(installer.versions)
+ def _update_requests_add_installers(self, scenario):
+ scenario.installers = self._update_with_body(models.ScenarioInstaller,
+ 'installer',
+ scenario.installers)
+
+ def _update_requests_update_installers(self, scenario):
+ scenario.installers = self._update_with_body(models.ScenarioInstaller,
+ 'installer',
+ list())
+
+ def _update_requests_delete_installers(self, scenario):
+ scenario.installers = self._remove_installers(scenario.installers)
+
def _update_with_body(self, clazz, field, withs):
exists = list()
malformat = list()
@@ -272,6 +301,9 @@ class ScenarioUpdater(object):
def _filter_installers(self, installers):
return self._filter('installer', installers)
+ def _remove_installers(self, installers):
+ return self._remove('installer', installers)
+
def _filter_versions(self, versions):
return self._filter('version', versions)
@@ -688,3 +720,56 @@ class ScenarioVersionsHandler(GenericScenarioUpdateHandler):
'delete',
locators={'scenario': scenario,
'installer': None})
+
+
+class ScenarioInstallersHandler(GenericScenarioUpdateHandler):
+ @swagger.operation(nickname="addInstallersUnderScenario")
+ def post(self, scenario):
+ """
+ @description: add installers to scenario
+ @notes: add one or multiple installers
+ POST /api/v1/scenarios/<scenario_name>/installers
+ @param body: installers to be added
+ @type body: C{list} of L{ScenarioInstaller}
+ @in body: body
+ @return 200: installers are added.
+ @raise 400: bad schema
+ @raise 409: conflict, installer already exists
+ @raise 404: scenario not exist
+ """
+ self.do_update('installers',
+ 'post',
+ locators={'scenario': scenario})
+
+ @swagger.operation(nickname="updateInstallersUnderScenario")
+ def put(self, scenario):
+ """
+ @description: replace all installers
+ @notes: substitute all installers as a totality
+ PUT /api/v1/scenarios/<scenario_name>/installers
+ @param body: new installers
+ @type body: C{list} of L{ScenarioInstaller}
+ @in body: body
+ @return 200: replace versions success.
+ @raise 400: bad schema
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('installers',
+ 'put',
+ locators={'scenario': scenario})
+
+ @swagger.operation(nickname="deleteInstallersUnderScenario")
+ def delete(self, scenario):
+ """
+ @description: delete one or multiple installers
+ @notes: delete one or multiple installers
+ DELETE /api/v1/scenarios/<scenario_name>/installers
+ @param body: installers(names) to be deleted
+ @type body: C{list} of L{string}
+ @in body: body
+ @return 200: delete versions success.
+ @raise 404: scenario/installer not exist
+ """
+ self.do_update('installers',
+ 'delete',
+ locators={'scenario': scenario})
diff --git a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
index c6da76b81..d950ed1d7 100644
--- a/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
+++ b/utils/test/testapi/opnfv_testapi/resources/scenario_models.py
@@ -167,6 +167,12 @@ class ScenarioChangeOwnerRequest(models.ModelBase):
@swagger.model()
+class ScenarioUpdateRequest(models.ModelBase):
+ def __init__(self, name=None):
+ self.name = name
+
+
+@swagger.model()
class Scenario(models.ModelBase):
"""
@property installers: