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