OpenSecurity/bin/test_vmmanager.pyw
author BarthaM@N3SIM1218.D03.arc.local
Thu, 17 Jul 2014 10:20:10 +0100
changeset 212 59ebaa44c12c
child 213 2e0b94e12bfc
permissions -rw-r--r--
Modified update_template to cope with unattached .vmdk
Added start method to vmmanager
Modified vmmanager to not start automatically over getInstance() invocation
Modified cygwin to corectly get the root folder (OpenSecurity//bin)
     1 #!/bin/env python
     2 # -*- coding: utf-8 -*-
     3 
     4 # ------------------------------------------------------------
     5 # opensecurityd
     6 #   
     7 # the opensecurityd as RESTful server
     8 #
     9 # Autor: Mihai Bartha, <mihai.bartha@ait.ac.at>       
    10 #
    11 # Copyright (C) 2013 AIT Austrian Institute of Technology
    12 # AIT Austrian Institute of Technology GmbH
    13 # Donau-City-Strasse 1 | 1220 Vienna | Austria
    14 # http://www.ait.ac.at
    15 #
    16 # This program is free software; you can redistribute it and/or
    17 # modify it under the terms of the GNU General Public License
    18 # as published by the Free Software Foundation version 2.
    19 # 
    20 # This program is distributed in the hope that it will be useful,
    21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    23 # GNU General Public License for more details.
    24 # 
    25 # You should have received a copy of the GNU General Public License
    26 # along with this program; if not, write to the Free Software
    27 # Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    28 # Boston, MA  02110-1301, USA.
    29 # ------------------------------------------------------------
    30 
    31 
    32 # ------------------------------------------------------------
    33 # imports
    34 
    35 import unittest
    36 
    37 import os
    38 import os.path
    39 import sys
    40 import cygwin
    41 import vmmanager
    42 gvm_mgr = None
    43 
    44 class TestVMManager(unittest.TestCase):
    45     
    46     def setUp(self):
    47         pass
    48     
    49     @classmethod
    50     def setUpClass(self):
    51         global gvm_mgr
    52         gvm_mgr = vmmanager.VMManager.getInstance()
    53         pass
    54     
    55     @unittest.skip("skipping")
    56     def testGetTemplateUUID(self):
    57         template = vmmanager.VMManager.getTemplateUUID()
    58         self.assertIsNotNone(template,  "returned no UUID for template")
    59     
    60     #@unittest.skip("skipping (requires running vmmanager)")    
    61     def testUpdateTemplate(self):
    62         gvm_mgr.updateTemplate()
    63         pass
    64     
    65     #@classmethod
    66     #def tearOffClass(self):
    67     #    gvm_mgr.stop()
    68     #    gvm_mgr.cleanup()
    69         
    70 
    71 if __name__ == '__main__':
    72     TestVMManager.setUpClass()
    73     
    74     suite = unittest.TestLoader().loadTestsFromTestCase(TestVMManager)
    75     unittest.TextTestRunner().run(suite)
    76     
    77 #    logger = setupLogger('Cygwin')
    78 #    c = Cygwin()
    79 #    unittest.main()
    80     #man = VMManager.getInstance()
    81     #man.listVM()
    82     #print man.getConnectedRSDs()
    83     #print man.getNetworkDrives()
    84     #man.genNetworkDrive()
    85     #drive_bitmask = ctypes.cdll.kernel32.GetLogicalDrives()
    86     #print list(itertools.compress(string.ascii_uppercase,  map(lambda x:ord(x) - ord('0'), bin(drive_bitmask)[:1:-1])))
    87     #print list(map(chr, range(68, 91))) 
    88     #print Cygwin.getRegEntry('SYSTEM\CurrentControlSet\Enum\USB', 'VID_1058&PID_0704')[0]
    89     #devices = VMManager.getConnectedRSDS()
    90     #print devices
    91     
    92     #drives = VMManager.getLogicalDrives()
    93     #print drives
    94     #print VMManager.getDriveType("E")
    95     #print VMManager.getVolumeInfo("E")
    96     #print VMManager.getNetworkPath("E")
    97     
    98     #vmm.backupFile()
    99     #for device in devices.values():
   100     #    #print device
   101     #    if VMManager.isMassStorageDevice(device):
   102     #        print device
   103         
   104     
   105     
   106     #time.sleep(-1)
   107     #man.listVM()
   108     #man.listVM()
   109     #man.listVM()
   110     #man.listVM()
   111     #man.genCertificateISO('SecurityDVM0')
   112     #man.guestExecute('SecurityDVM0', '/bin/ls -la')
   113     #logger = setupLogger('VMManager')
   114     #c = Cygwin()
   115     
   116     #man.sshExecute('/bin/ls -la', 'SecurityDVM0')
   117     #man.sshExecuteX11('/usr/bin/iceweasel', 'SecurityDVM0')
   118     #man.removeVM('SecurityDVM0')
   119     #man.netUse('192.168.56.134', 'USB\\')
   120     #ip = '192.168.56.139'
   121     
   122     #man.cygwin_path = 'c:\\cygwin64\\bin\\'
   123     #man.handleDeviceChange()
   124     #print man.listSDVM()
   125     #man.configureHostNetworking()
   126     #new_vm = man.generateSDVMName()
   127     #man.createVM(new_vm)
   128     
   129     #print Cygwin.cmd()
   130     #man.isAvailable('c:')
   131     #ip = man.getHostOnlyIP('SecurityDVM0')
   132     #man.mapNetworkDrive('h:', '\\\\' + ip + '\Download', None, None)
   133     
   134     #man.genCertificateISO(new_vm)
   135     #man.attachCertificateISO(new_vm)
   136     
   137     #man.attachCertificateISO(vm_name)
   138     #man.guestExecute(vm_name, "ls")
   139     #man.sshGuestX11Execute('SecurityDVM1', '/usr/bin/iceweasel')
   140     #time.sleep(60)
   141     #print man.cygwinPath("C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\.ssh\*")
   142     #man.genCertificateISO('SecurityDVM')
   143     #man.attachCertificateISO('SecurityDVM')
   144     #man.isStorageAttached('SecurityDVM')
   145     #man.guestExecute('SecurityDVM', 'sudo apt-get -y update')
   146     #man.guestExecute('SecurityDVM', 'sudo apt-get -y upgrade' )
   147     
   148     #man.stopVM('SecurityDVM')
   149     #man.storageDetach('SecurityDVM')
   150     #man.changeStorageType('C:\Users\BarthaM\VirtualBox VMs\SecurityDVM\SecurityDVM.vmdk','immutable')
   151     #man.storageAttach('SecurityDVM')
   152     
   153     
   154     #cmd = "c:\\cygwin64\\bin\\bash.exe --login -c \"/bin/ls\""
   155     #man.execute(cmd)