def test_get_serial_console_image_nport_exceed(self, get_serial_console): get_serial_console.side_effect = ( exception.ImageSerialPortNumberExceedFlavorValue()) body = {'os-getSerialConsole': {'type': 'serial'}} self._check_console_failure('self.controller.get_serial_console', webob.exc.HTTPBadRequest, body) self.assertTrue(get_serial_console.called)
def test_create_console_nport_exceed(self, mock_get): mock_handler = mock.MagicMock() mock_handler.side_effect = ( exception.ImageSerialPortNumberExceedFlavorValue()) self.controller.handlers['serial'] = mock_handler body = {'remote_console': {'protocol': 'serial', 'type': 'serial'}} self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, self.req, fakes.FAKE_UUID, body=body)
def test_get_serial_console_image_nport_exceed(self, get_serial_console): get_serial_console.side_effect = ( exception.ImageSerialPortNumberExceedFlavorValue()) body = {'os-getSerialConsole': {'type': 'serial'}} req = webob.Request.blank(self.url) req.method = "POST" req.body = jsonutils.dumps(body) req.headers["content-type"] = "application/json" res = req.get_response(self.app) self.assertEqual(res.status_int, 400) self.assertTrue(get_serial_console.called)
def get_number_of_serial_ports(flavor, image_meta): """Get the number of serial consoles from the flavor or image :param flavor: Flavor object to read extra specs from :param image_meta: Image object to read image metadata from If flavor extra specs is not set, then any image meta value is permitted. If flavour extra specs *is* set, then this provides the default serial port count. The image meta is permitted to override the extra specs, but *only* with a lower value. ie - flavor hw:serial_port_count=4 VM gets 4 serial ports - flavor hw:serial_port_count=4 and image hw_serial_port_count=2 VM gets 2 serial ports - image hw_serial_port_count=6 VM gets 6 serial ports - flavor hw:serial_port_count=4 and image hw_serial_port_count=6 Abort guest boot - forbidden to exceed flavor value :returns: number of serial ports """ def get_number(obj, property): num_ports = obj.get(property) if num_ports is not None: try: num_ports = int(num_ports) except ValueError: raise exception.ImageSerialPortNumberInvalid( num_ports=num_ports, property=property) return num_ports image_meta_prop = (image_meta or {}).get('properties', {}) flavor_num_ports = get_number(flavor.extra_specs, "hw:serial_port_count") image_num_ports = get_number(image_meta_prop, "hw_serial_port_count") if (flavor_num_ports and image_num_ports) is not None: if image_num_ports > flavor_num_ports: raise exception.ImageSerialPortNumberExceedFlavorValue() return image_num_ports return flavor_num_ports or image_num_ports or 1
def test_get_serial_console_image_nport_exceed(self): body = {'os-getSerialConsole': {'type': 'serial'}} self._check_console_failure( self.controller.get_serial_console, webob.exc.HTTPBadRequest, body, 'get_serial_console', exception.ImageSerialPortNumberExceedFlavorValue())