예제 #1
0
파일: test_host.py 프로젝트: otc-mfc/nova
 def test_event_lifecycle_callback_suspended_migrated(self):
     """Tests the suspended lifecycle event with libvirt with migrated"""
     hostimpl = mock.MagicMock()
     conn = mock.MagicMock()
     fake_dom_xml = """
             <domain type='kvm'>
               <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
             </domain>
         """
     dom = fakelibvirt.Domain(conn, fake_dom_xml, running=True)
     # See https://libvirt.org/html/libvirt-libvirt-domain.html for values.
     VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED = 1
     with mock.patch.object(host.libvirt,
                            'VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED',
                            new=1,
                            create=True):
         host.Host._event_lifecycle_callback(
             conn,
             dom,
             fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED,
             detail=VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED,
             opaque=hostimpl)
     expected_event = hostimpl._queue_event.call_args[0][0]
     # FIXME(mriedem): This should be EVENT_LIFECYCLE_MIGRATION_COMPLETED
     # once bug 1788014 is fixed and we properly check job status for the
     # VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED case.
     # self.assertEqual(event.EVENT_LIFECYCLE_MIGRATION_COMPLETED,
     #                  expected_event.transition)
     self.assertEqual(event.EVENT_LIFECYCLE_PAUSED,
                      expected_event.transition)
예제 #2
0
파일: test_host.py 프로젝트: otc-mfc/nova
 def emulate_defineXML(xml):
     conn = self.host.get_connection()
     # Emulate the decoding behavior of defineXML in Python2
     if six.PY2:
         xml = xml.decode("utf-8")
     dom = fakelibvirt.Domain(conn, xml, False)
     return dom
예제 #3
0
    def test_event_lifecycle(self):
        got_events = []

        # Validate that libvirt events are correctly translated
        # to Nova events
        def handler(event):
            got_events.append(event)

        hostimpl = host.Host("qemu:///system", lifecycle_event_handler=handler)
        conn = hostimpl.get_connection()

        hostimpl._init_events_pipe()
        fake_dom_xml = """
                <domain type='kvm'>
                  <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
                  <devices>
                    <disk type='file'>
                      <source file='filename'/>
                    </disk>
                  </devices>
                </domain>
            """
        dom = fakelibvirt.Domain(conn, fake_dom_xml, False)

        hostimpl._event_lifecycle_callback(conn, dom,
                                           libvirt.VIR_DOMAIN_EVENT_STOPPED, 0,
                                           hostimpl)
        hostimpl._dispatch_events()
        self.assertEqual(len(got_events), 1)
        self.assertIsInstance(got_events[0], event.LifecycleEvent)
        self.assertEqual(got_events[0].uuid,
                         "cef19ce0-0ca2-11df-855d-b19fbce37686")
        self.assertEqual(got_events[0].transition,
                         event.EVENT_LIFECYCLE_STOPPED)
예제 #4
0
파일: test_host.py 프로젝트: daespinel/nova
 def test_event_lifecycle_callback_suspended_migrated_job_failed(
         self, find_job_type, get_job_info):
     """Tests the suspended lifecycle event with libvirt with migrated"""
     hostimpl = mock.MagicMock()
     conn = mock.MagicMock()
     fake_dom_xml = """
             <domain type='kvm'>
               <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
             </domain>
         """
     dom = fakelibvirt.Domain(conn, fake_dom_xml, running=True)
     jobinfo = libvirt_guest.JobInfo(type=fakelibvirt.VIR_DOMAIN_JOB_NONE)
     get_job_info.return_value = jobinfo
     # If the job type is VIR_DOMAIN_JOB_NONE we'll attempt to figure out
     # the actual job status, so in this case we mock it to be a failure.
     find_job_type.return_value = fakelibvirt.VIR_DOMAIN_JOB_FAILED
     host.Host._event_lifecycle_callback(
         conn,
         dom,
         fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED,
         detail=fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED,
         opaque=hostimpl)
     expected_event = hostimpl._queue_event.call_args[0][0]
     self.assertEqual(event.EVENT_LIFECYCLE_PAUSED,
                      expected_event.transition)
     get_job_info.assert_called_once_with()
     find_job_type.assert_called_once_with(test.MatchType(
         libvirt_guest.Guest),
                                           instance=None,
                                           logging_ok=False)
예제 #5
0
    def setUp(self):
        super(MigrationMonitorTestCase, self).setUp()

        self.useFixture(fakelibvirt.FakeLibvirtFixture())

        flavor = objects.Flavor(memory_mb=2048,
                                swap=0,
                                vcpu_weight=None,
                                root_gb=1,
                                id=2,
                                name=u'm1.small',
                                ephemeral_gb=0,
                                rxtx_factor=1.0,
                                flavorid=u'1',
                                vcpus=1,
                                extra_specs={})

        instance = {
            'id': 1,
            'uuid': '32dfcb37-5af1-552b-357c-be8c3aa38310',
            'memory_kb': '1024000',
            'basepath': '/some/path',
            'bridge_name': 'br100',
            'display_name': "Acme webserver",
            'vcpus': 2,
            'project_id': 'fake',
            'bridge': 'br101',
            'image_ref': '155d900f-4e14-4e4c-a73d-069cbf4541e6',
            'root_gb': 10,
            'ephemeral_gb': 20,
            'instance_type_id': '5',  # m1.small
            'extra_specs': {},
            'system_metadata': {
                'image_disk_format': 'raw',
            },
            'flavor': flavor,
            'new_flavor': None,
            'old_flavor': None,
            'pci_devices': objects.PciDeviceList(),
            'numa_topology': None,
            'config_drive': None,
            'vm_mode': None,
            'kernel_id': None,
            'ramdisk_id': None,
            'os_type': 'linux',
            'user_id': '838a72b0-0d54-4827-8fd6-fb1227633ceb',
            'ephemeral_key_uuid': None,
            'vcpu_model': None,
            'host': 'fake-host',
            'task_state': None,
        }
        self.instance = objects.Instance(**instance)
        self.conn = fakelibvirt.Connection("qemu:///system")
        self.dom = fakelibvirt.Domain(self.conn, "<domain/>", True)
        self.host = host.Host("qemu:///system")
        self.guest = libvirt_guest.Guest(self.dom)
예제 #6
0
 def test_write_instance_config(self, mock_defineXML):
     fake_dom_xml = """
             <domain type='kvm'>
               <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
               <devices>
                 <disk type='file'>
                   <source file='filename'/>
                 </disk>
               </devices>
             </domain>
         """
     conn = self.host.get_connection()
     dom = fakelibvirt.Domain(conn, fake_dom_xml, False)
     mock_defineXML.return_value = dom
     guest = self.host.write_instance_config(fake_dom_xml)
     mock_defineXML.assert_called_once_with(fake_dom_xml)
     self.assertIsInstance(guest, libvirt_guest.Guest)
예제 #7
0
 def test_event_lifecycle_callback_suspended_postcopy(self):
     """Tests the suspended lifecycle event with libvirt with post-copy"""
     hostimpl = mock.MagicMock()
     conn = mock.MagicMock()
     fake_dom_xml = """
             <domain type='kvm'>
               <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
             </domain>
         """
     dom = fakelibvirt.Domain(conn, fake_dom_xml, running=True)
     host.Host._event_lifecycle_callback(
         conn, dom, fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED,
         detail=fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY,
         opaque=hostimpl)
     expected_event = hostimpl._queue_event.call_args[0][0]
     self.assertEqual(event.EVENT_LIFECYCLE_POSTCOPY_STARTED,
                      expected_event.transition)
예제 #8
0
    def test_event_lifecycle(self):
        got_events = []

        # Validate that libvirt events are correctly translated
        # to Nova events
        def spawn_after(seconds, func, *args, **kwargs):
            got_events.append(args[0])
            return mock.Mock(spec=greenthread.GreenThread)

        greenthread.spawn_after = mock.Mock(side_effect=spawn_after)
        hostimpl = host.Host("qemu:///system",
                             lifecycle_event_handler=lambda e: None)
        conn = hostimpl.get_connection()

        hostimpl._init_events_pipe()
        fake_dom_xml = """
                <domain type='kvm'>
                  <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
                  <devices>
                    <disk type='file'>
                      <source file='filename'/>
                    </disk>
                  </devices>
                </domain>
            """
        dom = fakelibvirt.Domain(conn,
                                 fake_dom_xml,
                                 False)

        hostimpl._event_lifecycle_callback(
            conn, dom, fakelibvirt.VIR_DOMAIN_EVENT_STOPPED, 0, hostimpl)
        hostimpl._dispatch_events()
        self.assertEqual(len(got_events), 1)
        self.assertIsInstance(got_events[0], event.LifecycleEvent)
        self.assertEqual(got_events[0].uuid,
                         "cef19ce0-0ca2-11df-855d-b19fbce37686")
        self.assertEqual(got_events[0].transition,
                         event.EVENT_LIFECYCLE_STOPPED)
예제 #9
0
파일: test_host.py 프로젝트: daespinel/nova
 def test_event_lifecycle_callback_suspended_migrated(self, get_job_info):
     """Tests the suspended lifecycle event with libvirt with migrated"""
     hostimpl = mock.MagicMock()
     conn = mock.MagicMock()
     fake_dom_xml = """
             <domain type='kvm'>
               <uuid>cef19ce0-0ca2-11df-855d-b19fbce37686</uuid>
             </domain>
         """
     dom = fakelibvirt.Domain(conn, fake_dom_xml, running=True)
     jobinfo = libvirt_guest.JobInfo(
         type=fakelibvirt.VIR_DOMAIN_JOB_COMPLETED)
     get_job_info.return_value = jobinfo
     host.Host._event_lifecycle_callback(
         conn,
         dom,
         fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED,
         detail=fakelibvirt.VIR_DOMAIN_EVENT_SUSPENDED_MIGRATED,
         opaque=hostimpl)
     expected_event = hostimpl._queue_event.call_args[0][0]
     self.assertEqual(event.EVENT_LIFECYCLE_MIGRATION_COMPLETED,
                      expected_event.transition)
     get_job_info.assert_called_once_with()