@@ -35,7 +35,7 @@ def _create_ctx(self):
3535 'libvirt_auth' : {'a' : 'c' }
3636 },
3737 runtime_properties = DirtyTrackingDict ({
38- 'params' : {'c' : "d" , 'e' : 'g' , 'memory_size' : 1024 },
38+ 'params' : {'c' : "d" , 'e' : 'g' },
3939 'libvirt_auth' : {'a' : 'd' }
4040 })
4141 )
@@ -47,10 +47,11 @@ def test_reuse_domain_create_not_exist(self):
4747 _ctx = self ._create_ctx ()
4848 self ._check_no_such_object_domain (
4949 "cloudify_libvirt.domain_tasks.libvirt.open" ,
50- domain_tasks .configure , [], {'ctx' : _ctx , 'params' : {
50+ domain_tasks .configure , [], {
51+ 'ctx' : _ctx ,
5152 "resource_id" : 'resource' ,
52- "use_external_resource" : True ,
53- }} , 'resource' )
53+ "use_external_resource" : True
54+ }, 'resource' )
5455
5556 def test_reuse_domain_create_exist (self ):
5657 # check that we can use domain
@@ -65,9 +66,8 @@ def test_reuse_domain_create_exist(self):
6566 "cloudify_libvirt.domain_tasks.libvirt.open" ,
6667 mock .Mock (return_value = connect )
6768 ):
68- domain_tasks .configure (ctx = _ctx , params = {
69- "resource_id" : 'resource' ,
70- "use_external_resource" : True })
69+ domain_tasks .configure (ctx = _ctx , resource_id = 'resource' ,
70+ use_external_resource = True )
7171 connect .lookupByName .assert_called_with ('resource' )
7272 self .assertEqual (
7373 _ctx .instance .runtime_properties ['resource_id' ], 'resource'
@@ -86,7 +86,7 @@ def test_create(self):
8686 self .assertEqual (_ctx .instance .runtime_properties , {
8787 'libvirt_auth' : {'w' : 'x' },
8888 'params' : {
89- 'a' : 'b' , 'c' : 'd' , 'e' : 'g' , 'z' : 'y' , 'memory_size' : 1024
89+ 'a' : 'b' , 'c' : 'd' , 'e' : 'g' , 'z' : 'y'
9090 }
9191 })
9292
@@ -114,17 +114,61 @@ def test_configure(self):
114114
115115 connect = self ._create_fake_connection ()
116116 connect .defineXML = mock .Mock (return_value = domain )
117+
118+ # without params
117119 _ctx .instance .runtime_properties ['params' ] = {}
118120 _ctx .node .properties ['params' ] = {}
119121 with mock .patch (
120122 "cloudify_libvirt.domain_tasks.libvirt.open" ,
121123 mock .Mock (return_value = connect )
122124 ):
123- domain_tasks .configure (ctx = _ctx , domain_file = "domain_file" )
125+ domain_tasks .configure (ctx = _ctx ,
126+ domain_file = "domain_file" )
124127 connect .defineXML .assert_called_with ('<somexml/>' )
125128 self .assertEqual (
126129 _ctx .instance .runtime_properties ['resource_id' ], "domain_name"
127130 )
131+ # with params from inputs
132+ _ctx .instance .runtime_properties ['params' ] = {}
133+ _ctx .node .properties ['params' ] = {}
134+ with mock .patch (
135+ "cloudify_libvirt.domain_tasks.libvirt.open" ,
136+ mock .Mock (return_value = connect )
137+ ):
138+ domain_tasks .configure (ctx = _ctx ,
139+ domain_file = "domain_file" ,
140+ params = {"memory_size" : 1024 })
141+ connect .defineXML .assert_called_with ('<somexml/>' )
142+ self .assertEqual (
143+ _ctx .instance .runtime_properties ['params' ]['memory_maxsize' ],
144+ 2048 )
145+ self .assertEqual (
146+ _ctx .instance .runtime_properties ['params' ]['memory_size' ],
147+ 1024 )
148+
149+
150+ def test_update (self ):
151+ self ._test_no_resource_id (domain_tasks .update )
152+ self ._test_check_correct_connect_action (domain_tasks .update )
153+ self ._test_check_correct_connect_no_object (domain_tasks .update )
154+ # check memory
155+ self ._test_action_states (
156+ domain_tasks .update ,
157+ [libvirt .VIR_DOMAIN_RUNNING ],
158+ 'Can not change memory amount.' ,
159+ params_update = {'memory_size' : 1024 })
160+ # check max memory
161+ self ._test_action_states (
162+ domain_tasks .update ,
163+ [libvirt .VIR_DOMAIN_RUNNING_UNKNOWN ],
164+ 'Can not change max memory amount.' ,
165+ params_update = {'memory_maxsize' : 1024 })
166+ # check cpu
167+ self ._test_action_states (
168+ domain_tasks .update ,
169+ [libvirt .VIR_DOMAIN_RUNNING_UNKNOWN ],
170+ 'Can not change cpu count.' ,
171+ params_update = {'vcpu' : 1024 })
128172
129173 def test_reboot (self ):
130174 self ._test_no_resource_id (domain_tasks .reboot )
@@ -378,10 +422,12 @@ def test_update_network_list(self):
378422 )
379423
380424 def _test_action_states (self , func , states , error_text ,
381- error_check_ip = None ):
425+ error_check_ip = None , params_update = None ):
382426 _ctx = self ._create_ctx ()
383427 _ctx .instance .runtime_properties ['resource_id' ] = 'check'
384428 _ctx .instance .runtime_properties ['params' ]['wait_for_ip' ] = True
429+ if params_update :
430+ _ctx .instance .runtime_properties ['params' ].update (params_update )
385431 fake_states = [state for state in states ]
386432
387433 def _fake_state ():
@@ -401,6 +447,9 @@ def _fake_state():
401447 domain .resume = mock .Mock (return_value = - 1 )
402448 domain .suspend = mock .Mock (return_value = - 1 )
403449 domain .reboot = mock .Mock (return_value = - 1 )
450+ domain .setMemory = mock .Mock (return_value = - 1 )
451+ domain .setMaxMemory = mock .Mock (return_value = - 1 )
452+ domain .setVcpus = mock .Mock (return_value = - 1 )
404453
405454 with mock .patch (
406455 "cloudify_libvirt.domain_tasks.libvirt.open" ,
@@ -419,6 +468,9 @@ def _fake_state():
419468 domain .resume = mock .Mock (return_value = 0 )
420469 domain .suspend = mock .Mock (return_value = 0 )
421470 domain .reboot = mock .Mock (return_value = 0 )
471+ domain .setMemory = mock .Mock (return_value = 0 )
472+ domain .setMaxMemory = mock .Mock (return_value = 0 )
473+ domain .setVcpus = mock .Mock (return_value = 0 )
422474 fake_states = [state for state in states ]
423475
424476 def _fake_state ():
0 commit comments