[Kimchi-devel] [kimchi-devel][PATCHv2] Fix update vcpu count: Check available vcpu count before update

Aline Manera alinefm at linux.vnet.ibm.com
Thu Mar 26 19:38:07 UTC 2015


I can't apply it.
Please, rebase on master branch and resend.

Thanks,
Aline Manera

On 24/03/2015 06:53, lvroyce at linux.vnet.ibm.com wrote:
> From: Royce Lv <lvroyce at linux.vnet.ibm.com>
>
> Currently we just check vcpu count does not exceed host available
> count when topology specified.
> Actually vcpu count also need to be checked when only vcpu specified.
> Move this check outside topology check and add it to param update.
>
> Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
> ---
>   src/kimchi/model/cpuinfo.py   | 8 ++++++--
>   src/kimchi/model/templates.py | 6 +++---
>   tests/test_model.py           | 2 +-
>   tests/test_rest.py            | 1 -
>   4 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/src/kimchi/model/cpuinfo.py b/src/kimchi/model/cpuinfo.py
> index 3411ef5..54bfad4 100644
> --- a/src/kimchi/model/cpuinfo.py
> +++ b/src/kimchi/model/cpuinfo.py
> @@ -114,11 +114,15 @@ class CPUInfoModel(object):
>           cores = topology['cores']
>           threads = topology['threads']
>
> +        self.check_vcpus(vcpus)
> +
>           if not self.guest_threads_enabled:
>               raise InvalidOperation("KCHCPUINF0003E")
>           if vcpus != sockets * cores * threads:
>               raise InvalidParameter("KCHCPUINF0002E")
> -        if vcpus > self.cores_available * self.threads_per_core:
> -            raise InvalidParameter("KCHCPUINF0001E")
>           if threads > self.threads_per_core:
>               raise InvalidParameter("KCHCPUINF0002E")
> +
> +    def check_vcpus(self, vcpus):
> +        if vcpus > self.cores_available * self.threads_per_core:
> +            raise InvalidParameter("KCHCPUINF0001E")
> diff --git a/src/kimchi/model/templates.py b/src/kimchi/model/templates.py
> index 6bc8aca..14e5b37 100644
> --- a/src/kimchi/model/templates.py
> +++ b/src/kimchi/model/templates.py
> @@ -53,7 +53,7 @@ class TemplatesModel(object):
>                                              {'filename': iso, 'user': user,
>                                               'err': excp})
>
> -        cpu_info = params.get('cpu_info')
> +        cpu_info = params.setdefault('cpu_info', dict())
>           if cpu_info:
>               topology = cpu_info.get('topology')
>               # Check, even though currently only topology
> @@ -68,8 +68,8 @@ class TemplatesModel(object):
>                   # exception if a topology is invalid.
>                   CPUInfoModel(conn=self.conn).\
>                       check_topology(params['cpus'], topology)
> -        else:
> -            params['cpu_info'] = dict()
> +        if params.get('cpus'):
> +            CPUInfoModel(conn=self.conn).check_vcpus(params['cpus'])
>
>           conn = self.conn.get()
>           pool_uri = params.get(u'storagepool', '')
> diff --git a/tests/test_model.py b/tests/test_model.py
> index 0020022..138a7da 100644
> --- a/tests/test_model.py
> +++ b/tests/test_model.py
> @@ -577,7 +577,7 @@ class ModelTests(unittest.TestCase):
>           inst = model.Model(None,
>                              objstore_loc=self.tmp_store)
>
> -        orig_params = {'name': 'test', 'memory': '1024', 'cpus': '1',
> +        orig_params = {'name': 'test', 'memory': '1024', 'cpus': 1,
>                          'cdrom': UBUNTU_ISO}
>           inst.templates_create(orig_params)
>
> diff --git a/tests/test_rest.py b/tests/test_rest.py
> index 07e5733..4ecf3ce 100644
> --- a/tests/test_rest.py
> +++ b/tests/test_rest.py
> @@ -932,7 +932,6 @@ class RestTests(unittest.TestCase):
>           task_info = model.storagevolumes_create('pool-3', params)
>           wait_task(self._task_lookup, task_info['id'])
>
> -
>           storagevolume = json.loads(self.request(
>               '/storagepools/kimchi_isos/storagevolumes/').read())[0]
>           self.assertEquals('fedora.iso', storagevolume['name'])




More information about the Kimchi-devel mailing list