Example #1
0
def fake_libvirt_conn(moxobj, count=1):
    conn = moxobj.CreateMockAnything()
    conn._conn = moxobj.CreateMockAnything()
    moxobj.StubOutWithMock(libvirt, 'get_libvirt_connection')
    for _ in xrange(count):
        libvirt.get_libvirt_connection().AndReturn(conn)
    return conn
Example #2
0
    def test_get_counters(self):
        interface_stats1 = (3876L, 15L, 0L, 0L, 15830L, 0L, 0L, 0L)
        interface_stats2 = (9999L, 99L, 0L, 0L, 88888L, 0L, 0L, 0L)
        vnics = [{
            'name': 'vnet0',
            'ip': '10.0.0.2',
            'projmask': '255.255.255.0',
            'projnet': 'proj1',
            'fref': 'nova-instance-instance-00000001-fa163e71ec6e',
            'bridge': 'br100',
            'dhcp_server': '10.0.0.1',
            'alias': 'net0',
            'mac': 'fa:16:3e:71:ec:6d'
        }, {
            'name': 'vnet1',
            'ip': '192.168.0.3',
            'projmask': '255.255.255.0',
            'projnet': 'proj2',
            'fref': 'nova-instance-instance-00000001-fa163e71ec6f',
            'bridge': 'br100',
            'dhcp_server': '192.168.0.1',
            'fref': '00:00:00:01:1e',
            'alias': 'net1',
            'mac': 'fa:16:3e:71:ec:6e'
        }]

        ignore = mox.IgnoreArg()
        conn = self.mox.CreateMockAnything()
        conn._conn = self.mox.CreateMockAnything()
        domain = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(libvirt, 'get_libvirt_connection')
        libvirt.get_libvirt_connection().AndReturn(conn)
        self.mox.StubOutWithMock(self.pollster, '_get_vnics')
        self.pollster._get_vnics(ignore, ignore).AndReturn(vnics)
        self.mox.StubOutWithMock(conn._conn, 'lookupByName')
        conn._conn.lookupByName(self.instance.name).AndReturn(domain)
        self.mox.StubOutWithMock(domain, 'interfaceStats')
        domain.interfaceStats('vnet0').AndReturn(interface_stats1)
        domain.interfaceStats('vnet1').AndReturn(interface_stats2)
        self.mox.ReplayAll()

        results = list(self.pollster.get_counters(self.manager, self.instance))
        self.assertTrue([countr.resource_metadata['ip'] for countr in results])
        self.assertTrue([countr.resource_id for countr in results])
Example #3
0
    def test_get_counters(self):
        interface_stats1 = (3876L, 15L, 0L, 0L, 15830L, 0L, 0L, 0L)
        interface_stats2 = (9999L, 99L, 0L, 0L, 88888L, 0L, 0L, 0L)
        vnics = [
                 {'name': 'vnet0',
                  'ip': '10.0.0.2',
                  'projmask': '255.255.255.0',
                  'projnet': 'proj1',
                  'fref': 'nova-instance-instance-00000001-fa163e71ec6e',
                  'bridge': 'br100',
                  'dhcp_server': '10.0.0.1',
                  'alias': 'net0',
                  'mac': 'fa:16:3e:71:ec:6d'},
                 {'name': 'vnet1',
                  'ip': '192.168.0.3',
                  'projmask': '255.255.255.0',
                  'projnet': 'proj2',
                  'fref': 'nova-instance-instance-00000001-fa163e71ec6f',
                  'bridge': 'br100',
                  'dhcp_server': '192.168.0.1',
                  'fref': '00:00:00:01:1e',
                  'alias': 'net1',
                  'mac': 'fa:16:3e:71:ec:6e'}
                ]

        ignore = mox.IgnoreArg()
        conn = self.mox.CreateMockAnything()
        conn._conn = self.mox.CreateMockAnything()
        domain = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(libvirt, 'get_libvirt_connection')
        libvirt.get_libvirt_connection().AndReturn(conn)
        self.mox.StubOutWithMock(self.pollster, '_get_vnics')
        self.pollster._get_vnics(ignore, ignore).AndReturn(vnics)
        self.mox.StubOutWithMock(conn._conn, 'lookupByName')
        conn._conn.lookupByName(self.instance.name).AndReturn(domain)
        self.mox.StubOutWithMock(domain, 'interfaceStats')
        domain.interfaceStats('vnet0').AndReturn(interface_stats1)
        domain.interfaceStats('vnet1').AndReturn(interface_stats2)
        self.mox.ReplayAll()

        results = list(self.pollster.get_counters(self.manager, self.instance))
        self.assertTrue([countr.resource_metadata['ip'] for countr in results])
        self.assertTrue([countr.resource_id for countr in results])