Ejemplo n.º 1
0
 def test_get_registered(self):
     dm = DockerMonitor()
     n = 5
     for i in range(n):
         dm.register(MagicMock())
     registered = dm.get_registered()
     self.assertEqual(len(registered), n)
Ejemplo n.º 2
0
    def test_register_vm(self):
        mock_vm = MagicMock()

        dm = DockerMonitor()
        dm.register(mock_vm)
        registered = dm.get_registered()

        # Asserts
        self.assertEqual(len(registered), 1)
        self.assertEqual(registered.pop(), mock_vm)
Ejemplo n.º 3
0
    def test_start_monitoring(self, mstart_new_thread, mxenapiclient,
                              log_info):
        mvm_ref = MagicMock()
        dm = DockerMonitor(host=MagicMock())

        dm.start_monitoring(mvm_ref)
        registered = dm.get_registered()[0]

        mstart_new_thread.assert_called_with(registered._monitoring_loop,
                                             tuple())
Ejemplo n.º 4
0
    def test_load_one_vm(self, mprocess_vmrecord):
        host = MagicMock()

        mvm_rec = MagicMock()

        host.client.get_all_vm_records.return_value = {'test_rec': mvm_rec}

        dm = DockerMonitor(host)
        dm.refresh()

        host.client.get_all_vm_records.assert_called_once_with()
        mprocess_vmrecord.assert_called_with('test_rec', mvm_rec)
Ejemplo n.º 5
0
    def test_load_all_vm(self, mprocess_vmrecord):
        host = MagicMock()

        # Mock out the vm_ref: vm_rec dictionary object
        mvm_recs = {}
        n = 10
        for i in range(n):
            mvm_recs["rec_%d" % i] = MagicMock()

        host.client.get_all_vm_records.return_value = mvm_recs

        dm = DockerMonitor(host)
        dm.refresh()

        host.client.get_all_vm_records.assert_called_once_with()

        # Assert we process every record.
        self.assertEqual(mprocess_vmrecord.call_count, n)
Ejemplo n.º 6
0
    def test_unregister_vm(self):
        mock_vm = MagicMock()

        dm = DockerMonitor()
        dm.register(mock_vm)
        dm.deregister(mock_vm)
        registered = dm.get_registered()

        self.assertEqual(registered, [])
Ejemplo n.º 7
0
    def test_stop_monitoring(self, log_info):
        mvm_ref = MagicMock()
        dm = DockerMonitor()
        thevm = MonitoredVM(MagicMock(), ref=mvm_ref)

        dm.register(thevm)
        dm.stop_monitoring(mvm_ref)

        self.assertEqual(thevm._stop_monitoring_request, ["stop"])
Ejemplo n.º 8
0
 def test_deregistration_exception(self):
     mock_vm = MagicMock()
     dm = DockerMonitor()
     dm.deregister(mock_vm)
     self.assertRaises(Exception, dm.deregister(mock_vm))
Ejemplo n.º 9
0
 def test_is_registered(self):
     mock_vm = MagicMock()
     dm = DockerMonitor()
     self.assertEqual(dm.is_registered(mock_vm), False)
     dm.register(mock_vm)
     self.assertEqual(dm.is_registered(mock_vm), True)