Skip to content

Commit

Permalink
Merge pull request #535 from grycap/devel
Browse files Browse the repository at this point in the history
Fix #534
  • Loading branch information
micafer authored Apr 23, 2024
2 parents 1b0b473 + 4996cc5 commit 1679a76
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
19 changes: 14 additions & 5 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
from functools import wraps
from urllib.parse import urlparse
from radl import radl_parse
from radl.radl import deploy, description
from radl.radl import deploy, description, Feature
from flask_apscheduler import APScheduler
from flask_wtf.csrf import CSRFProtect, CSRFError
from toscaparser.tosca_template import ToscaTemplate
Expand Down Expand Up @@ -394,11 +394,20 @@ def managevm(op=None, infid=None, vmid=None):
form_data = request.form.to_dict()
cpu = int(form_data['cpu'])
memory = int(form_data['memory'])
system_name = form_data['system_name']

radl = "system %s (cpu.count >= %d and memory.size >= %dg and instance_type = '')" % (system_name,
cpu, memory)
response = im.resize_vm(infid, vmid, radl, auth_data)
vminforesp = im.get_vm_info(infid, vmid, auth_data, "text/plain")
if vminforesp.ok:
vminfo = radl_parse.parse_radl(vminforesp.text)
vminfo.systems[0].delValue("instance_type")
vminfo.systems[0].delValue("cpu.count")
vminfo.systems[0].addFeature(Feature("cpu.count", ">=", cpu),
conflict="other", missing="other")
vminfo.systems[0].delValue("memory.size")
vminfo.systems[0].addFeature(Feature("memory.size", ">=", memory, "GB"),
conflict="other", missing="other")
response = im.resize_vm(infid, vmid, str(vminfo), auth_data)
else:
raise Exception("Error getting VM info: %s" % vminforesp.text)
else:
response = im.manage_vm(op, infid, vmid, auth_data)
except Exception as ex:
Expand Down
4 changes: 2 additions & 2 deletions app/im.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def get_inf_state(self, infid, auth_data):
inf_state = response.json()
return inf_state['state']

def get_vm_info(self, infid, vmid, auth_data):
headers = {"Authorization": auth_data, "Accept": "application/json"}
def get_vm_info(self, infid, vmid, auth_data, accept="application/json"):
headers = {"Authorization": auth_data, "Accept": accept}
url = "%s/infrastructures/%s/vms/%s" % (self.im_url, infid, vmid)
return requests.get(url, headers=headers, timeout=self.timeout)

Expand Down
1 change: 0 additions & 1 deletion app/templates/vminfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ <h5 class="modal-title" id="managevm_resize_label">VM resize</h5>
</div>
<form id="resizeVM" action="{{ url_for('managevm', op='resize', infid=infid, vmid=vmid) }}" method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<input type="hidden" name="system_name" value="{{ system_name }}"/>
<div class="modal-body">

<div class="row form-group">
Expand Down
6 changes: 4 additions & 2 deletions app/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_response(url, params=None, **kwargs):
elif url == "/im/infrastructures/infid/vms/0":
resp.ok = True
resp.status_code = 200
resp.text = ""
resp.text = "system front (cpu.count = 1 and memory.size = 512 MB)"
radl = {"class": "system",
"cpu.arch": "x86_64",
"cpu.count_min": 1,
Expand Down Expand Up @@ -328,12 +328,14 @@ def test_managevm_delete(self, flash, avatar, delete, user_data):
'success'))

@patch("app.utils.getUserAuthData")
@patch('requests.get')
@patch('requests.put')
@patch("app.utils.avatar")
@patch("app.flash")
def test_managevm_resize(self, flash, avatar, put, user_data):
def test_managevm_resize(self, flash, avatar, put, get, user_data):
user_data.return_value = "type = InfrastructureManager; token = access_token"
put.side_effect = self.put_response
get.side_effect = self.get_response
self.login(avatar)
params = {'cpu': '4',
'memory': '4',
Expand Down

0 comments on commit 1679a76

Please sign in to comment.