コード例 #1
0
    def test_eagerness(self):
        self.db_store.get_one.return_value = ModelTest(
            id='id1', topic='topic1')

        ModelTestProxy(id='id1', lazy=False)
        self.db_store.get_one.assert_called_once_with(ModelTest(id='id1'))

        self.db_store.get_one.reset_mock()
        model_proxy.create_reference(ModelTest, lazy=False, id='id1')
        self.db_store.get_one.assert_called_once_with(ModelTest(id='id1'))
コード例 #2
0
    def test__is_physical_chassis(self, get_one):
        # real chassis
        chassis_real = core.Chassis(id='ch1', ip='10.0.0.3')
        self.assertTrue(self.controller._is_physical_chassis(chassis_real))

        self.db_store = mock.MagicMock()
        get_one.return_value = core.Chassis(id='ch2', ip='10.0.0.4')
        chassis_ref = model_proxy.create_reference(core.Chassis, 'ch2')
        self.assertTrue(self.controller._is_physical_chassis(chassis_ref))

        get_one.return_value = None
        chassis_bad_ref = model_proxy.create_reference(core.Chassis, 'ch3')
        self.assertFalse(self.controller._is_physical_chassis(chassis_bad_ref))
コード例 #3
0
 def test_null_comparison(self):
     # The following test must be assertNotEquals (and not assertIsNotNone)
     # since we test the flow via the __eq__ function. assertIsNotNone tests
     # using 'is', which doesn't use the __eq__ function flow.
     self.assertNotEqual(model_proxy.create_reference(ModelTest, '4321'),
                      None)  # noqa: H203
     m = RefferingModel(other_field='hi there')
     ref = ModelTest(id='1234', topic='3')
     m1 = RefferingModel(model_test=ref)
     m.update(m1)
     self.assertEqual('1234', m.model_test.id)
コード例 #4
0
    def test_proxied_attrs(self):
        self.db_store.get_one.return_value = ModelTest(
            id='id1', topic='topic1')

        mtp = ModelTestProxy(id='id1')
        self.assertEqual('id1', mtp.id)
        self.assertEqual('topic1', mtp.topic)
        self.db_store.get_one.assert_called_once_with(ModelTest(id='id1'))

        self.db_store.get_one.reset_mock()
        mtp = model_proxy.create_reference(ModelTest, id='id1')
        self.assertEqual('id1', mtp.id)
        self.assertEqual('topic1', mtp.topic)
        self.db_store.get_one.assert_called_once_with(ModelTest(id='id1'))
コード例 #5
0
 def test_is_model_proxy(self):
     model_instance = ModelTest(id='id1', topic='topic1')
     self.assertFalse(model_proxy.is_model_proxy(model_instance))
     model_ref = model_proxy.create_reference(ModelTest, id='id1')
     self.assertTrue(model_proxy.is_model_proxy(model_ref))
コード例 #6
0
 def test_none_reference(self):
     self.assertIsNone(model_proxy.create_reference(ModelTest, id=None))
     self.assertIsNone(model_proxy.create_reference(ModelTest))
コード例 #7
0
def make_fake_local_port(**kargs):
    kargs['is_local'] = True
    return make_fake_port(**kargs)


fake_local_port1_dhcp_opts = [
    l2.DHCPOption(tag=3, value='10.0.0.1'),
    l2.DHCPOption(tag=121, value='0.0.0.0/0,10.0.0.1'),
]

fake_local_port1 = make_fake_local_port(
    macs=['fa:16:3e:8c:2e:b3'],
    ips=['10.0.0.6', '2222:2222::3'],
    network_type='vxlan',
    subnets=[model_proxy.create_reference(l2.Subnet, 'fake_subnet1')],
    id='fake_port1',
    extra_dhcp_opts=fake_local_port1_dhcp_opts)

fake_ovs_port1 = ovs.OvsPort(
    id='fake_ovs_port1',
    ofport=2,
    name='tap-fake_port1',
    admin_state='up',
    type=constants.OVS_VM_INTERFACE,
    iface_id='fake_port1',
    attached_mac='fa:16:3e:8c:2e:b3',
    tunnel_type='vxlan',
)

fake_local_port2 = make_fake_local_port(macs=['fa:16:3e:8c:2e:b4'],