[Kimchi-devel] [PATCH v4] [Kimchi] Feature request (#860): Support Guest Autostart

Aline Manera alinefm at linux.vnet.ibm.com
Wed Aug 31 20:08:20 UTC 2016


Hi Bianca,

The tests cases are failing with this patch:

======================================================================
FAIL: test_edit_vm (test_rest.HttpsRestTests)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "test_rest.py", line 306, in test_edit_vm
     self.assertEquals(200, resp.status)
AssertionError: 200 != 404

======================================================================
FAIL: test_edit_vm (test_rest.RestTests)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "test_rest.py", line 306, in test_edit_vm
     self.assertEquals(200, resp.status)
AssertionError: 200 != 404

======================================================================
FAIL: test_vm_info (test_mockmodel.MockModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "test_mockmodel.py", line 174, in test_vm_info
     self.assertEquals(keys, set(info.keys()))
AssertionError: Items in the second set but not the first:
'autostart'

======================================================================
FAIL: test_vm_edit (test_model.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "test_model.py", line 1367, in test_vm_edit
     self.assertEquals("yes", inst.vm_lookup(u'пeω-∨м')['autostart'])
AssertionError: 'yes' != 1

======================================================================
FAIL: test_vm_info (test_model.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "test_model.py", line 138, in test_vm_info
     self.assertEquals(keys, set(info.keys()))
AssertionError: Items in the second set but not the first:
'autostart'

----------------------------------------------------------------------

Could you check that and resend the patch?

Regards,
Aline Manera

On 08/31/2016 04:39 PM, bianca at linux.vnet.ibm.com wrote:
> From: Bianca Carvalho <bianca at linux.vnet.ibm.com>
>
> Include 'autostart' option in API.json and vms.py (lookup and update)
> using libvirt dom.setAutostart to set as true or false. Also edit
> test_model.py to include those changes and updated API.md file.
> Also included API tests to test_rest.py in test_edit_vm function.
>
> Signed-off-by: Bianca Carvalho <bianca at linux.vnet.ibm.com>
> ---
>   API.json            |  4 ++++
>   docs/API.md         |  3 +++
>   model/vms.py        | 11 ++++++++---
>   tests/test_model.py |  6 ++++++
>   tests/test_rest.py  | 18 ++++++++++++++++++
>   5 files changed, 39 insertions(+), 3 deletions(-)
>
> diff --git a/API.json b/API.json
> index a3af02d..8592f3a 100644
> --- a/API.json
> +++ b/API.json
> @@ -342,6 +342,10 @@
>                       "error": "KCHVM0053E",
>                       "type": "boolean"
>                   },
> +                "autostart": {
> +                  "description": "Enable/Disable guest autostart",
> +                  "type": "boolean"
> +                },
>                   "users": {
>                       "description": "Array of users who have permission to the VM",
>                       "type": "array",
> diff --git a/docs/API.md b/docs/API.md
> index 7bd677f..7c29f04 100644
> --- a/docs/API.md
> +++ b/docs/API.md
> @@ -151,6 +151,8 @@ server.
>       * bootorder: list of devices in boot order
>       * description: VM description
>       * title: VM title
> +    * autostart: show if autostart is enabled.
> +
>   * **DELETE**: Remove the Virtual Machine
>   * **PUT**: update the parameters of existing VM
>       * name: New name for this VM (only applied for shutoff VM)
> @@ -183,6 +185,7 @@ server.
>       * bootmenu: prompts guest bootmenu. Bool type.
>       * description: VM description
>       * title: VM title
> +    * autostart: enable/disable guest autostart (true or false params).
>
>   * **POST**: *See Virtual Machine Actions*
>
> diff --git a/model/vms.py b/model/vms.py
> index 7f607f5..bb00c09 100644
> --- a/model/vms.py
> +++ b/model/vms.py
> @@ -80,12 +80,13 @@ DOM_STATE_MAP = {0: 'nostate',
>                    7: 'pmsuspended'}
>
>   # update parameters which are updatable when the VM is online
> -VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users']
> +VM_ONLINE_UPDATE_PARAMS = ['graphics', 'groups', 'memory', 'users',
> +                           'autostart']
>
>   # update parameters which are updatable when the VM is offline
>   VM_OFFLINE_UPDATE_PARAMS = ['cpu_info', 'graphics', 'groups', 'memory',
>                               'name', 'users', 'bootorder', 'bootmenu',
> -                            'description', 'title']
> +                            'description', 'title', 'autostart']
>
>   XPATH_DOMAIN_DISK = "/domain/devices/disk[@device='disk']/source/@file"
>   XPATH_DOMAIN_DISK_BY_FILE = "./devices/disk[@device='disk']/source[@file='%s']"
> @@ -270,6 +271,9 @@ class VMModel(object):
>
>           with lock:
>               dom = self.get_vm(name, self.conn)
> +            if "autostart" in params:
> +                dom.setAutostart(1 if params['autostart'] == True else 0)
> +
>               # You can only change <maxMemory> offline, updating guest XML
>               if ("memory" in params) and ('maxmemory' in params['memory']) and\
>                  (DOM_STATE_MAP[dom.info()[0]] != 'shutoff'):
> @@ -1314,7 +1318,8 @@ class VMModel(object):
>                   'access': 'full',
>                   'persistent': True if dom.isPersistent() else False,
>                   'bootorder': boot,
> -                'bootmenu': bootmenu
> +                'bootmenu': bootmenu,
> +                'autostart': dom.autostart()
>                   }
>
>       def _vm_get_disk_paths(self, dom):
> diff --git a/tests/test_model.py b/tests/test_model.py
> index d9ffd5e..8f3a578 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -1362,6 +1362,12 @@ class ModelTests(unittest.TestCase):
>               inst.vm_update(u'пeω-∨м', {"bootmenu": False})
>               self.assertEquals("no", inst.vm_lookup(u'пeω-∨м')['bootmenu'])
>
> +            # enable/disable autostart
> +            inst.vm_update(u'пeω-∨м', {"autostart": True})
> +            self.assertEquals("yes", inst.vm_lookup(u'пeω-∨м')['autostart'])
> +            inst.vm_update(u'пeω-∨м', {"autostart": False})
> +            self.assertEquals("no", inst.vm_lookup(u'пeω-∨м')['autostart'])
> +
>       def test_get_interfaces(self):
>           inst = model.Model('test:///default',
>                              objstore_loc=self.tmp_store)
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index b1b9f12..0ecf11b 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -301,6 +301,24 @@ class RestTests(unittest.TestCase):
>           resp = self.request('/plugins/kimchi/vms/∨м-црdαtеd', req, 'PUT')
>           self.assertEquals(400, resp.status)
>
> +        # set vm autostart tests (powered off)
> +        resp = self.request('/plugins/kimchi/vms/vm-1/poweroff', '{}', 'POST')
> +        self.assertEquals(200, resp.status)
> +        req = json.dumps({"autostart": True})
> +        resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
> +        self.assertEquals(200, resp.status)
> +        resp = self.request('/plugins/kimchi/vms/vm-1', '{}', 'GET').read()
> +        self.assertEquals(resp["autostart"], True)
> +
> +        # set vm autostart tests (running)
> +        resp = self.request('/plugins/kimchi/vms/vm-1/start', '{}', 'POST')
> +        self.assertEquals(200, resp.status)
> +        req = json.dumps({"autostart": False})
> +        resp = self.request('/plugins/kimchi/vms/vm-1', req, 'PUT')
> +        self.assertEquals(200, resp.status)
> +        resp = self.request('/plugins/kimchi/vms/vm-1', '{}', 'GET').read()
> +        self.assertEquals(resp["autostart"], True)
> +
>       def test_vm_lifecycle(self):
>           # Create a Template
>           req = json.dumps({'name': 'test',




More information about the Kimchi-devel mailing list