# Copyright (C) International Business Machines Corp., 2006
# Author: Stefan Berger <*****@*****.**>

# Basic VM creation test

from XmTestLib import xapi
from XmTestLib.XenAPIDomain import XmTestAPIDomain
from XmTestLib import *
from xen.xend import XendAPIConstants
import commands
import os

try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain = XmTestAPIDomain()
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))
vm_uuid = domain.get_uuid()

session = xapi.connect()

domain.start(startpaused=True)

res = session.xenapi.VM.get_power_state(vm_uuid)

if res != XendAPIConstants.XEN_API_VM_POWER_STATE[XendAPIConstants.XEN_API_VM_POWER_STATE_PAUSED]:
    FAIL("VM was not started in 'paused' state")

res = session.xenapi.VM.unpause(vm_uuid)
예제 #2
0
header = session.xenapi.ACMPolicy.get_header(xs_ref)

if header['policyname'] != xm_test['policyname']:
    FAIL("Name in header is '%s', expected is '%s'." %
         (header['policyname'], xm_test['policyname']))
if header['date'] != xm_test['date']:
    FAIL("Date in header is '%s', expected is '%s'." %
         (header['date'], xm_test['date']))
if header.has_key("url") and header['url'] != xm_test['url']:
    FAIL("URL  in header is '%s', expected is '%s'." %
         (header['url'], xm_test['url']))

# Create another domain
try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain = XmTestAPIDomain(extraConfig={'security_label': vm_label_blue})
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))

vm_uuid = domain.get_uuid()

res = session.xenapi.VM.get_security_label(vm_uuid)
if res != vm_label_blue:
    FAIL("VM has security label '%s', expected is '%s'" % (res, vm_label_blue))

try:
    domain.start(noConsole=True)
except:
    FAIL("Could not create domain")

# Attempt to relabel the running domain
header = session.xenapi.ACMPolicy.get_header(xs_ref)

if header['policyname'] != xm_test['policyname']:
    FAIL("Name in header is '%s', expected is '%s'." %
         (header['policyname'],xm_test['policyname']))
if header['date'] != xm_test['date']:
    FAIL("Date in header is '%s', expected is '%s'." %
         (header['date'],xm_test['date']))
if header.has_key("url") and header['url' ] != xm_test['url' ]:
    FAIL("URL  in header is '%s', expected is '%s'." %
         (header['url' ],xm_test['url' ]))

# Create another domain
try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain = XmTestAPIDomain(extraConfig={ 'security_label' : vm_label_blue })
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))


vm_uuid = domain.get_uuid()

res = session.xenapi.VM.get_security_label(vm_uuid)
if res != vm_label_blue:
    FAIL("VM has security label '%s', expected is '%s'" %
         (res, vm_label_blue))

try:
    domain.start(noConsole=True)
except:
    FAIL("Could not create domain")
예제 #4
0
# VDI: create, get_name_label, destroy
#
# VBD: create, get_mode, get_VM, get_VDI, get_device
#
# VM: get_VBDs

from XmTestLib import xapi
from XmTestLib.XenAPIDomain import XmTestAPIDomain
from XmTestLib import *
from xen.xend import XendAPIConstants
import commands
import os

try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain = XmTestAPIDomain()
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))

vm_uuid = domain.get_uuid()

session = xapi.connect()

# Do something with SR/VDI/VBD

sr_uuid = session.xenapi.SR.get_by_name_label("Local")
if len(sr_uuid) == 0:
    FAIL("Could not get a handle on SR 'Local'")

vdi_rec = {
    'name_label': "My disk",
예제 #5
0
    ip_addr_2 = "172.16.77.71"
    default_gateway = "172.16.77.72"
    default_netmask = "255.255.255.0"

    @staticmethod
    def remove_network(guest):
        nw = guest.session.xenapi.network.get_all()
        for n in nw:
            name = guest.session.xenapi.network.get_name_label(n)
            if name == TCConfig.network_name:
                guest.session.xenapi.network.destroy(n)


# Create two domains (default XmTestDomain, with our ramdisk)
try:
    guest1 = XmTestAPIDomain()
    console1 = guest1.start()
    #    guest1.newDevice(XenNetDevice, "eth0")
    #    guest1_netdev = guest1.getDevice("eth0")
    guest2 = XmTestAPIDomain()
    console2 = guest2.start()
except DomainError, e:
    if verbose:
        print("Failed to create test domain because: %s" % e.extra)
    FAIL(str(e))

# Clean up relicts
TCConfig.remove_network(guest1)

# Create a network
network = guest1.session.xenapi.network.create(
예제 #6
0
# VDI: create, get_name_label, destroy
#
# VBD: create, get_driver, get_mode, get_VM, get_VDI, get_device
#
# VM: get_VBDs

from XmTestLib import xapi
from XmTestLib.XenAPIDomain import XmTestAPIDomain
from XmTestLib import *
from xen.xend import XendAPIConstants
import commands
import os

try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain = XmTestAPIDomain()
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))

vm_uuid = domain.get_uuid()

session = xapi.connect()

# Do something with SR/VDI/VBD

sr_uuid = session.xenapi.SR.get_by_name_label("Local")
if len(sr_uuid) == 0:
    FAIL("Could not get a handle on SR 'Local'")

vdi_rec = { 'name_label'  : "My disk",
            'SR'          : sr_uuid[0],
kernel_orig_uri = arch.configDefaults['kernel']
ramdisk_orig_uri = arch.configDefaults['ramdisk']
kernel_data_uri = scheme_data.create_from_file(kernel_orig_uri)
ramdisk_data_uri = scheme_data.create_from_file(ramdisk_orig_uri)
kernel_file_uri = scheme_file.encode(kernel_orig_uri)
ramdisk_file_uri = scheme_file.encode(ramdisk_orig_uri)

config = copy.copy(arch.configDefaults)

for kernel in (kernel_orig_uri, kernel_data_uri, kernel_file_uri):
    for ramdisk in (ramdisk_orig_uri, ramdisk_data_uri, ramdisk_file_uri):
        config['kernel'] = kernel
        config['ramdisk'] = ramdisk
        print("Using kernel='%s' ramdisk='%s'" % (kernel[:100], ramdisk[:100]))
        try:
            guest = XmTestAPIDomain(baseConfig = config)
            console = guest.start()
        except DomainError, e:
            if verbose:
                print("Failed to create test domain because: %s" % e.extra)
            FAIL(str(e))

        try:
            run = console.runCmd("ls /")
            if run['return'] > 0:
                FAIL("Could not start host")
        except ConsoleError, e:
            saveLog(console.getHistory())
            FAIL(str(e))
            
        guest.closeConsole()
policystate = session.xenapi.XSPolicy.set_xspolicy(xsconstants.XS_POLICY_ACM,
                                                   xml,
                                                   xsconstants.XS_INST_LOAD,
                                                   True)

print "\n\npolicystate = %s" % policystate

policystate = session.xenapi.XSPolicy.get_xspolicy()

#
# Create two non-conflicting domains and start them
#
try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain1 = XmTestAPIDomain(extraConfig={ 'security_label' : vm_label_red })
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))


vm1_uuid = domain1.get_uuid()

try:
    domain1.start(noConsole=True)
except:
    FAIL("Could not start domain1")

print "Domain 1 started"

try:
    # XmTestAPIDomain tries to establish a connection to XenD
vdi_label_green = xsconstants.ACM_POLICY_ID + ":xm-test:green"

vm_label_unlabeled = xsconstants.ACM_POLICY_ID + ":xm-test:" + \
                     acmpolicy.ACM_LABEL_UNLABELED

vdi_file = "/dev/ram0"
vdi_path = "phy:" + vdi_file

#Note:
# If during the suspend/resume operations 'red' instead of 'green' is
# used, the Chinese Wall policy goes into effect and disallows the
# suspended VM from being resumed...

try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain = XmTestAPIDomain(extraConfig={ 'security_label' : vm_label_red })
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))

vm_uuid = domain.get_uuid()

session = xapi.connect()
xstype = session.xenapi.XSPolicy.get_xstype()
if int(xstype) & xsconstants.XS_POLICY_ACM == 0:
    SKIP("ACM not enabled/compiled in Xen")

f = open("xm-test-security_policy.xml", 'r')
if f:
    newpolicyxml = f.read()
    f.close()
else:
vdi_label_green = xsconstants.ACM_POLICY_ID + ":xm-test:green"

vm_label_unlabeled = xsconstants.ACM_POLICY_ID + ":xm-test:" + \
                     acmpolicy.ACM_LABEL_UNLABELED

vdi_file = "/dev/ram0"
vdi_path = "phy:" + vdi_file

#Note:
# If during the suspend/resume operations 'red' instead of 'green' is
# used, the Chinese Wall policy goes into effect and disallows the
# suspended VM from being resumed...

try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain = XmTestAPIDomain(extraConfig={'security_label': vm_label_red})
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))

vm_uuid = domain.get_uuid()

session = xapi.connect()
xstype = session.xenapi.XSPolicy.get_xstype()
if int(xstype) & xsconstants.XS_POLICY_ACM == 0:
    SKIP("ACM not enabled/compiled in Xen")

f = open("xm-test-security_policy.xml", 'r')
if f:
    newpolicyxml = f.read()
    f.close()
else:
예제 #11
0
# Copyright (C) International Business Machines Corp., 2006
# Author: Stefan Berger <*****@*****.**>

# Basic VM creation test

from XmTestLib import xapi
from XmTestLib.XenAPIDomain import XmTestAPIDomain
from XmTestLib import *
from xen.xend import XendAPIConstants
import commands
import os

try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain = XmTestAPIDomain()
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))
vm_uuid = domain.get_uuid()

session = xapi.connect()

domain.start(startpaused=True)

res = session.xenapi.VM.get_power_state(vm_uuid)

if res != XendAPIConstants.XEN_API_VM_POWER_STATE[
        XendAPIConstants.XEN_API_VM_POWER_STATE_PAUSED]:
    FAIL("VM was not started in 'paused' state")

res = session.xenapi.VM.unpause(vm_uuid)
kernel_orig_uri = arch.configDefaults['kernel']
ramdisk_orig_uri = arch.configDefaults['ramdisk']
kernel_data_uri = scheme_data.create_from_file(kernel_orig_uri)
ramdisk_data_uri = scheme_data.create_from_file(ramdisk_orig_uri)
kernel_file_uri = scheme_file.encode(kernel_orig_uri)
ramdisk_file_uri = scheme_file.encode(ramdisk_orig_uri)

config = copy.copy(arch.configDefaults)

for kernel in (kernel_orig_uri, kernel_data_uri, kernel_file_uri):
    for ramdisk in (ramdisk_orig_uri, ramdisk_data_uri, ramdisk_file_uri):
        config['kernel'] = kernel
        config['ramdisk'] = ramdisk
        print("Using kernel='%s' ramdisk='%s'" % (kernel[:100], ramdisk[:100]))
        try:
            guest = XmTestAPIDomain(baseConfig=config)
            console = guest.start()
        except DomainError, e:
            if verbose:
                print("Failed to create test domain because: %s" % e.extra)
            FAIL(str(e))

        try:
            run = console.runCmd("ls /")
            if run['return'] > 0:
                FAIL("Could not start host")
        except ConsoleError, e:
            saveLog(console.getHistory())
            FAIL(str(e))

        guest.closeConsole()
예제 #13
0
policystate = session.xenapi.XSPolicy.set_xspolicy(xsconstants.XS_POLICY_ACM,
                                                   xml,
                                                   xsconstants.XS_INST_LOAD,
                                                   True)

print "\n\npolicystate = %s" % policystate

policystate = session.xenapi.XSPolicy.get_xspolicy()

#
# Create two non-conflicting domains and start them
#
try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain1 = XmTestAPIDomain(extraConfig={'security_label': vm_label_red})
except Exception, e:
    SKIP("Skipping test. Error: %s" % str(e))

vm1_uuid = domain1.get_uuid()

try:
    domain1.start(noConsole=True)
except:
    FAIL("Could not start domain1")

print "Domain 1 started"

try:
    # XmTestAPIDomain tries to establish a connection to XenD
    domain2 = XmTestAPIDomain(extraConfig={'security_label': vm_label_green})