Esempio n. 1
0
    def test(self):
        """Test debmarshal.privops.main.

    Beacuse this is so tied to the system dbus session, which we can't
    even get to as a non-privileged user, we pretty much have to mock
    out everything.
    """
        bus = self.mox.CreateMock(dbus.bus.BusConnection)
        name = self.mox.CreateMock(dbus.service.BusName)
        dbus_obj = self.mox.CreateMock(privops.Privops)
        loop = self.mox.CreateMock(gobject.MainLoop)

        self.mox.StubOutWithMock(dbus.mainloop.glib, 'DBusGMainLoop')
        self.mox.StubOutWithMock(dbus, 'SystemBus', use_mock_anything=True)
        self.mox.StubOutWithMock(dbus.service,
                                 'BusName',
                                 use_mock_anything=True)
        self.mox.StubOutWithMock(privops, 'Privops', use_mock_anything=True)
        self.mox.StubOutWithMock(gobject, 'MainLoop', use_mock_anything=True)
        self.mox.StubOutWithMock(gobject, 'timeout_add_seconds')

        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        dbus.SystemBus().AndReturn(bus)
        dbus.service.BusName(privops.DBUS_BUS_NAME, bus).AndReturn(name)
        privops.Privops(name, privops.DBUS_OBJECT_PATH).AndReturn(dbus_obj)
        gobject.MainLoop().AndReturn(loop)
        loop.run()

        self.mox.ReplayAll()

        privops.main()
Esempio n. 2
0
    def testNoNetwork(self):
        """Test that destroyNetwork doesn't try to delete a network it
    doesn't know about"""
        self.mox.ReplayAll()

        self.assertRaises(errors.NetworkNotFound,
                          privops.Privops().destroyNetwork, 'debmarshal-3')
Esempio n. 3
0
    def testNoNetwork(self):
        """Test destroyDomain with a nonexistent domain."""
        self.mox.ReplayAll()

        self.assertRaises(errors.DomainNotFound,
                          privops.Privops().destroyDomain, 'debmarshal-3',
                          'qemu')
Esempio n. 4
0
    def testNoPermissions(self):
        """Test destroyDomain with a network owned by someone else."""
        self.mox.StubOutWithMock(utils, 'getCaller')
        utils.getCaller().MultipleTimes().AndReturn(500)

        self.mox.ReplayAll()

        self.assertRaises(errors.AccessDenied,
                          privops.Privops().destroyDomain, 'debmarshal-1',
                          'qemu')
Esempio n. 5
0
    def testNoPermissions(self):
        """Test that destroyNetwork refuses to delete a network if you
    don't own it"""
        self.mox.StubOutWithMock(utils, 'getCaller')
        utils.getCaller().MultipleTimes().AndReturn(501)

        self.mox.ReplayAll()

        self.assertRaises(errors.AccessDenied,
                          privops.Privops().destroyNetwork, 'debmarshal-1')
Esempio n. 6
0
    def testStoreSuccess(self):
        """Test createNetwork when everything goes right"""
        self.mox.StubOutWithMock(utils, 'storeState')
        self.networks[self.name] = 1000
        utils.storeState(self.networks, 'debmarshal-networks')

        self.mox.ReplayAll()

        self.assertEqual(
            privops.Privops().createNetwork(self.hosts),
            (self.name, self.gateway, '255.255.255.0', self.host_dict))
Esempio n. 7
0
    def test(self):
        """Test privops.domains.createNetwork.

    With all of the functionality pulled into helper functions,
    createNetwork doesn't actually do all that much work.
    """
        name = 'debmarshal-12'
        memory = '128M'
        disks = ['/home/ebroder/root.img']
        net = 'debmarshal-0'
        mac = '00:11:22:33:44:55'

        self.mox.StubOutWithMock(utils, 'getCaller')
        utils.getCaller().MultipleTimes().AndReturn(500)
        self.mox.StubOutWithMock(debmarshal.utils, 'acquireLock')
        debmarshal.utils.acquireLock('debmarshal-domlist', fcntl.LOCK_EX)

        self.mox.StubOutWithMock(hypervisors.qemu.QEMU, 'open')
        qemu_con = self.mox.CreateMock(libvirt.virConnect)
        hypervisors.qemu.QEMU.open().AndReturn(qemu_con)

        self.mox.StubOutWithMock(domains, '_validateNetwork')
        domains._validateNetwork(net, qemu_con)

        self.mox.StubOutWithMock(domains, '_validatePath')
        for d in disks:
            domains._validatePath(d, os.R_OK | os.W_OK)

        self.mox.StubOutWithMock(domains, '_findUnusedName')
        domains._findUnusedName(qemu_con).AndReturn(name)

        self.mox.StubOutWithMock(hypervisors.qemu.QEMU, 'domainXMLString')
        hypervisors.qemu.QEMU.domainXMLString(
            mox.IgnoreArg()).AndReturn('<fake_xml/>')

        self.mox.StubOutWithMock(domains, 'loadDomainState')
        domains.loadDomainState().AndReturn({('debmarshal-1', 'qemu'): 500})

        self.mox.StubOutWithMock(utils, 'storeState')
        utils.storeState({
            ('debmarshal-1', 'qemu'): 500,
            (name, 'qemu'): 500
        }, 'debmarshal-domains')

        qemu_con.createLinux('<fake_xml/>', 0)

        self.mox.ReplayAll()

        self.assertEqual(
            privops.Privops().createDomain(memory, disks, net, mac, 'qemu',
                                           'x86_64', {}), name)
Esempio n. 8
0
    def testSuccess(self):
        """Test that destroyDomain can succeed."""
        self.mox.StubOutWithMock(utils, 'getCaller')
        utils.getCaller().MultipleTimes().AndReturn(500)

        virt_dom = self.mox.CreateMock(libvirt.virDomain)
        self.virt_con.lookupByName('debmarshal-0').AndReturn(virt_dom)
        virt_dom.destroy()

        self.mox.StubOutWithMock(utils, 'storeState')
        del self.domains[('debmarshal-0', 'qemu')]
        utils.storeState(self.domains, 'debmarshal-domains')

        self.mox.ReplayAll()

        privops.Privops().destroyDomain('debmarshal-0', 'qemu')
Esempio n. 9
0
    def testStoreFailure(self):
        """Test that the network is destroyed if state about it can't be
    stored"""
        self.mox.StubOutWithMock(utils, 'storeState')
        self.networks[self.name] = 1000
        utils.storeState(self.networks, 'debmarshal-networks').\
                         AndRaise(Exception("Error!"))

        self.virt_con.networkLookupByName(self.name).MultipleTimes().AndReturn(
            self.virt_net)
        self.virt_net.destroy()
        self.virt_net.undefine()

        self.mox.ReplayAll()

        self.assertRaises(Exception,
                          privops.Privops().createNetwork, self.hosts)
Esempio n. 10
0
    def testSuccess(self):
        """Test that destroyNetwork will actually delete an existing
    network owned by the right user."""
        self.mox.StubOutWithMock(utils, 'getCaller')
        utils.getCaller().MultipleTimes().AndReturn(501)

        virt_net = self.mox.CreateMock(libvirt.virNetwork)
        self.virt_con.networkLookupByName(
            'debmarshal-0').MultipleTimes().AndReturn(virt_net)
        virt_net.destroy()
        virt_net.undefine()

        self.mox.StubOutWithMock(utils, 'storeState')
        del self.networks['debmarshal-0']
        utils.storeState(self.networks, 'debmarshal-networks')

        self.mox.ReplayAll()

        privops.Privops().destroyNetwork('debmarshal-0')