[Kimchi-devel] [PATCH] Add software update action to Host resource

Aline Manera alinefm at linux.vnet.ibm.com
Tue Feb 18 12:28:27 UTC 2014


On 02/18/2014 05:28 AM, Sheldon wrote:
> comments below
>
> On 02/18/2014 06:37 AM, Aline Manera wrote:
>> From: Aline Manera <alinefm at br.ibm.com>
>>
>> Instead of handling the update packages action in
>> PackagesUpdate(Collection) move it to Host(Resource) to avoid
>> misunderstanding about the URI.
>>
>> >From /packagesupdate/update URI the "update" can be understood as the
>> resource item instead of the action.
>> So use /host/swupdate to update the packages marked to be updated.
>>
>> Signed-off-by: Aline Manera <alinefm at br.ibm.com>
>> ---
>>   docs/API.md                |    9 ++-------
>>   src/kimchi/control/host.py |   18 +++++++++---------
>>   src/kimchi/mockmodel.py    |    2 +-
>>   src/kimchi/model/host.py   |   34 ++++++++++++++++++----------------
>>   tests/test_mockmodel.py    |    2 +-
>>   tests/test_rest.py         |    2 +-
>>   6 files changed, 32 insertions(+), 35 deletions(-)
>>
>> diff --git a/docs/API.md b/docs/API.md
>> index 7f5e4d6..fff740d 100644
>> --- a/docs/API.md
>> +++ b/docs/API.md
>> @@ -709,6 +709,8 @@ Contains information of host.
>>             Only allowed if there is not vm running.
>>   * shutdown: Power off the host machine.
>>               Only allowed if there is not vm running.
>> +* swupdate: Start the update of packages in background and return a 
>> Task resource
>> +    * task resource.  * See Resource: Task *
>>
>>   ### Resource: HostStats
>>
>> @@ -813,13 +815,6 @@ Contains the information and action of packages 
>> update in the host.
>>
>>   * **GET**: Retrieves a list of all packages to be updated in the host:
>>
>> -* **POST**: *See Software Update Actions*
>> -
>> -**Actions (POST):**
>> -
>> -* update: Start the update of packages in background and return a 
>> Task resource
>> -    * task resource.  * See Resource: Task *
>> -
>>   ### Resource: Host Package Update
>>
>>   **URI:** /host/packagesupdate/*:name*
>> diff --git a/src/kimchi/control/host.py b/src/kimchi/control/host.py
>> index a705f59..70b549c 100644
>> --- a/src/kimchi/control/host.py
>> +++ b/src/kimchi/control/host.py
>> @@ -43,6 +43,15 @@ class Host(Resource):
>>           self.devices = Devices(self.model)
>>           self.packagesupdate = PackagesUpdate(self.model)
>>
>> +    @cherrypy.expose
>> +    def swupdate(self):
>> +        try:
>> +            task = self.model.host_swupdate()
>> +            cherrypy.response.status = 202
>> +            return render("Task", task)
>> +        except OperationFailed, e:
>> +            raise cherrypy.HTTPError(500, e.message)
>> +
> should we check this is a POST method?

Good point. I will fix it in v2.

>>       @property
>>       def data(self):
>>           return self.info
>> @@ -89,15 +98,6 @@ class PackagesUpdate(Collection):
>>           super(PackagesUpdate, self).__init__(model)
>>           self.resource = PackageUpdate
>>
>> -    @cherrypy.expose
>> -    def update(self):
>> -        try:
>> -            task = self.model.packagesupdate_update()
>> -            cherrypy.response.status = 202
>> -            return render("Task", task)
>> -        except OperationFailed, e:
>> -            raise cherrypy.HTTPError(500, e.message)
>> -
>>
>>   class PackageUpdate(Resource):
>>       def __init__(self, model, id=None):
>> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
>> index 0c2da8a..a0e5120 100644
>> --- a/src/kimchi/mockmodel.py
>> +++ b/src/kimchi/mockmodel.py
>> @@ -799,7 +799,7 @@ class MockModel(object):
>>       def packageupdate_lookup(self, pkg_name):
>>           return self._mock_swupdate.getUpdate(pkg_name)
>>
>> -    def packagesupdate_update(self, args=None):
>> +    def host_swupdate(self, args=None):
>>           task_id = self.add_task('', self._mock_swupdate.doUpdate, 
>> None)
>>           return self.task_lookup(task_id)
>>
>> diff --git a/src/kimchi/model/host.py b/src/kimchi/model/host.py
>> index ef40879..92121f6 100644
>> --- a/src/kimchi/model/host.py
>> +++ b/src/kimchi/model/host.py
>> @@ -67,6 +67,24 @@ class HostModel(object):
>>       def lookup(self, *name):
>>           return self.host_info
>>
>> +    def swupdate(self, *name):
>> +        try:
>> +            swupdate = SoftwareUpdate()
>> +        except:
>> +            raise OperationFailed('KCHPKGUPD0004E')
>> +
>> +        try:
>> +            pkgs = swupdate.getNumOfUpdates()
>> +        except OperationFailed, e:
>> +            raise e
>> +
>> +        if pkgs == 0:
>> +            raise OperationFailed('KCHPKGUPD0001E')
>> +
>> +        kimchi_log.debug('Host is going to be updated.')
>> +        taskid = add_task('', swupdate.doUpdate, self.objstore, None)
>> +        return self.task.lookup(taskid)
>> +
>>       def shutdown(self, args=None):
>>           # Check for running vms before shutdown
>>           running_vms = self._get_vms_list_by_state('running')
>> @@ -275,22 +293,6 @@ class PackagesUpdateModel(object):
>>
>>           return self.host_swupdate.getUpdates()
>>
>> -    def update(self, **kargs):
>> -        if self.host_swupdate is None:
>> -            raise OperationFailed('KCHPKGUPD0004E')
>> -
>> -        try:
>> -            pkgs = self.host_swupdate.getNumOfUpdates()
>> -        except OperationFailed, e:
>> -            raise e
>> -
>> -        if pkgs == 0:
>> -            raise OperationFailed('KCHPKGUPD0001E')
>> -
>> -        kimchi_log.debug('Host is going to be updated.')
>> -        taskid = add_task('', self.host_swupdate.doUpdate, 
>> self.objstore, None)
>> -        return self.task.lookup(taskid)
>> -
>>
>>   class PackageUpdateModel(object):
>>       def __init__(self, **kargs):
>> diff --git a/tests/test_mockmodel.py b/tests/test_mockmodel.py
>> index b985fe0..4ac08dd 100644
>> --- a/tests/test_mockmodel.py
>> +++ b/tests/test_mockmodel.py
>> @@ -164,6 +164,6 @@ class MockModelTests(unittest.TestCase):
>>               self.assertIn('arch', pkgupdate.keys())
>>               self.assertIn('version', pkgupdate.keys())
>>
>> -        task = model.packagesupdate_update()
>> +        task = model.host_swupdate()
>>           task_params = [u'id', u'message', u'status', u'target_uri']
>>           self.assertEquals(sorted(task_params), sorted(task.keys()))
>> diff --git a/tests/test_rest.py b/tests/test_rest.py
>> index 5aac211..26078d6 100644
>> --- a/tests/test_rest.py
>> +++ b/tests/test_rest.py
>> @@ -1467,7 +1467,7 @@ class RestTests(unittest.TestCase):
>>               self.assertIn('arch', info.keys())
>>               self.assertIn('version', info.keys())
>>
>> -        resp = self.request('/host/packagesupdate/update', '{}', 
>> 'POST')
>> +        resp = self.request('/host/swupdate', '{}', 'POST')
> you "DELETE", "GET" and "PUT" can also works here.
>>           task = json.loads(resp.read())
>>           task_params = [u'id', u'message', u'status', u'target_uri']
>>           self.assertEquals(sorted(task_params), sorted(task.keys()))
>
>




More information about the Kimchi-devel mailing list