Commit 7b1b261a by Jenkins Committed by Gerrit Code Review

Merge "Update podmanager controller to use generic interface"

parents 64b62755 64e5b718
......@@ -36,7 +36,7 @@ class PodManagersList(flask_restful.Resource):
def post(self):
values = flask.request.get_json()
return utils.make_response(http_client.OK,
class PodManager(flask_restful.Resource):
......@@ -48,9 +48,10 @@ class PodManager(flask_restful.Resource):
def patch(self, podm_uuid):
values = flask.request.get_json()
return utils.make_response(http_client.OK,
podmanagers.update_podm(podm_uuid, values))
def delete(self, podm_uuid):
resp_dict = exception.confirmation(confirm_detail="DELETED")
return utils.make_response(http_client.OK, resp_dict)
......@@ -118,7 +118,7 @@ def get_basic_auth_credentials(authentication):
"""parse out the basic auth from podm's authentication array properties
:param authentication: podm's authentication
:return: username, password to connect to the podm
:return: username, password to connect to podmanager
for auth_property in authentication:
if auth_property['type'] == constants.PODM_AUTH_BASIC_TYPE:
......@@ -14,10 +14,11 @@
import logging
from valence.common import constants
from valence.common import exception
from valence.common import utils
from valence.controller import nodes
from valence.db import api as db_api
from valence.redfish import redfish
from valence.podmanagers import manager
LOG = logging.getLogger(__name__)
......@@ -25,7 +26,6 @@ LOG = logging.getLogger(__name__)
def _check_creation(values):
"""Checking args when creating a new pod manager
authentication: should follow the format
name: can not be duplicated
url: can not be duplicated
......@@ -38,30 +38,10 @@ def _check_creation(values):
urls = [podm['url'] for podm in pod_manager_list]
if values['name'] in names or values['url'] in urls:
raise exception.BadRequest('duplicated name or url !')
# If podmanager 'driver' is None, update as "redfishv1" which is default
# driver used to manage resources.
# 'driver' can take values like "redfishv1", "redfishv2" etc.
values['driver'] = values.get('driver', 'redfishv1')
# input status
values['status'] = get_podm_status(values['url'], values['authentication'])
return values
def _check_updation(values):
"""Checking args when updating a exist pod manager
:values: The properties of pod manager to be updated
:returns: improved values that could be updated
# uuid, url can not be modified
if 'uuid' in values:
if 'url' in values:
return values
......@@ -73,35 +53,28 @@ def get_podm_by_uuid(uuid):
return db_api.Connection.get_podmanager_by_uuid(uuid).as_dict()
def create_podm(values):
def create_podmanager(values):
values = _check_creation(values)
username, password = utils.get_basic_auth_credentials(
# Retreive podm connection to get the status of podmanager
mng = manager.Manager(values['url'], username, password, values['driver'])
values['status'] = mng.podm.get_status()
return db_api.Connection.create_podmanager(values).as_dict()
def update_podm(uuid, values):
values = _check_updation(values)
def update_podmanager(uuid, values):
# Remove uuid and url from values as they can't be updated
for key in ['uuid', 'url']:
values.pop(key, None)
return db_api.Connection.update_podmanager(uuid, values).as_dict()
def delete_podm_by_uuid(uuid):
# TODO(hubian) this need to break the links between podm and its Nodes
return db_api.Connection.delete_podmanager(uuid)
def get_podm_status(url, authentication):
"""get pod manager running status by its url and auth
def delete_podmanager(uuid):
# For any cleanup driver needs to do (nodes cleanup), before deleting podm
p_nodes = db_api.Connection.list_composed_nodes({'podm_id': uuid})
# Delete the nodes w.r.t podmanager from valence DB
for node in p_nodes:
:param url: The url of pod manager.
:param authentication: array, The auth(s) info of pod manager.
:returns: status of the pod manager
for auth in authentication:
# TODO(Hubian) Only consider and support basic auth type here.
# After decided to support other auth type this would be improved.
if auth['type'] == constants.PODM_AUTH_BASIC_TYPE:
username = auth['auth_items']['username']
password = auth['auth_items']['password']
return redfish.pod_status(url, username, password)
return constants.PODM_STATUS_UNKNOWN
return db_api.Connection.delete_podmanager(uuid)
......@@ -23,6 +23,10 @@ class PodManagerBase(object):
# TODO(ramineni): rebase on nate's patch
def get_status(self):
def get_podm_info(self):
return self.get_resource_info_by_url(self.podm_url)
......@@ -15,7 +15,6 @@ import unittest
import mock
from valence.common import constants
from valence.common.exception import BadRequest
from valence.controller import podmanagers
......@@ -23,15 +22,13 @@ from valence.controller import podmanagers
class TestPodManagers(unittest.TestCase):
def test_check_creation(self, mock_get_podm_status, mock_get_podm_list):
def test_check_creation(self, mock_get_podm_list):
mock_get_podm_list.return_value = [
{"name": "test1",
"url": ""},
{"name": "test2",
"url": ""}
mock_get_podm_status.return_value = constants.PODM_STATUS_ONLINE
values = {"name": "podm_name",
"url": "",
......@@ -46,12 +43,9 @@ class TestPodManagers(unittest.TestCase):
result_values = copy.deepcopy(values)
result_values['status'] = constants.PODM_STATUS_ONLINE
result_values['driver'] = 'redfishv1'
self.assertEqual(podmanagers._check_creation(values), result_values)
......@@ -97,7 +91,8 @@ class TestPodManagers(unittest.TestCase):
self.assertEqual(mock_get_podm_list.call_count, 2)
def test_check_updation_ignore_url_uuid(self):
def test_check_updation_ignore_url_uuid(self, mock_db_update):
values = {
"uuid": "uuid",
"url": "url",
......@@ -107,39 +102,5 @@ class TestPodManagers(unittest.TestCase):
self.assertEqual(podmanagers._check_updation(values), result_values)
def test_get_podm_status(self, mock_pod_status):
mock_pod_status.return_value = constants.PODM_STATUS_ONLINE
authentication = [
"type": "basic",
"auth_items": {
"username": "username",
"password": "password"
self.assertEqual(podmanagers.get_podm_status('url', authentication),
mock_pod_status.asset_called_once_with('url', "username", "password")
def test_get_podm_status_unknown(self):
"""not basic type authentication podm status set value to be unknown"""
authentication = [
"type": "CertificateAuthority",
"auth_items": {
"public_key": "xxxxxxx"
"type": "DynamicCode",
"auth_items": {
"code": "xxxxxxx"
self.assertEqual(podmanagers.get_podm_status('url', authentication),
podmanagers.update_podmanager('fake-podm-id', values)
mock_db_update.assert_called_once_with('fake-podm-id', result_values)
......@@ -74,9 +74,9 @@ class TestFlavorApi(TestApiValidation):
class TestPodmanagerApi(TestApiValidation):
def test_podmanager_create(self, pstatus_mock, plist_mock, pcreate_mock):
pstatus_mock.return_value = constants.PODM_STATUS_ONLINE
plist_mock.return_value = []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment