vital2 / Vital-development

MIT License
18 stars 11 forks source link

Not handling an exception of VM creation gracefully #67

Open nikolai-sannikov opened 4 years ago

nikolai-sannikov commented 4 years ago

Not critical, just code cleanliness. I have managed to somehow ruin my test course (ironically, named 'The Best Course') and triggered an exception we maybe did not get in a while. In handling that exception we are referencing a missing attribute:

Unexpected error I have noticed: File "/home/vital/vital2.0/source/virtual_lab/vital_site/vital/views/student_view.py", line 198, in start_vm XenClient().remove_network_bridges(vm.xen_server, request.user, course_id, vm_id) AttributeError: 'Virtual_Machine' object has no attribute 'xen_server'

Code triggering error:

except Exception as e:
        logger.error(str(e))
        audit(request, 'Error starting Virtual machine ' + str(vm.name) + '( ' + e.message + ' )')
        if 'Connection refused' not in str(e).rstrip() or started_vm is not None:
            XenClient().remove_network_bridges(**vm.xen_server**, request.user, course_id, vm_id)
            XenClient().stop_vm(started_vm['xen_server'], request.user, course_id, vm_id)
        return redirect('/courses/' + course_id + '/vms?message=Unable to start VM - ' + vm.name)
suryansh1 commented 4 years ago

I just tried launching a standalone VM and connecting to it via VNC, and it is working(kali-test), so looks like something wrong with the course side logic.

test-qemu

nikolai-sannikov commented 4 years ago

Yep, and this is the point. If the course is working properly, this exception is never triggered and it is brushed under the carpet. But if the course config is ruined, it raises an exception, handling which includes a bad line I am talking about