def testReadFromFile_NoErr(self):
        s = ('[{'
             '  "ip_address": "174.12.14.1", '
             '  "user_name": "perfkitbenchmarker", '
             '  "keyfile_path": "perfkitbenchmarker.pem" '
             '}, '
             '{ '
             '   "ip_address": "174.12.14.121", '
             '   "user_name": "ubuntu", '
             '   "keyfile_path": "rackspace.pem", '
             '   "internal_ip": "10.10.10.2", '
             '   "zone": "rackspace_dallas" '
             '}] ')
        fp = StringIO(s)
        StaticVirtualMachine.ReadStaticVirtualMachineFile(fp)

        vm_pool = StaticVirtualMachine.vm_pool
        self.assertEqual(2, len(vm_pool))
        self._AssertStaticVMsEqual(
            StaticVirtualMachine(
                StaticVmSpec(_COMPONENT,
                             ip_address='174.12.14.1',
                             user_name='perfkitbenchmarker',
                             ssh_private_key='perfkitbenchmarker.pem')),
            vm_pool[0])
        self._AssertStaticVMsEqual(
            StaticVirtualMachine(
                StaticVmSpec(_COMPONENT,
                             ip_address='174.12.14.121',
                             user_name='ubuntu',
                             ssh_private_key='rackspace.pem',
                             internal_ip='10.10.10.2',
                             zone='rackspace_dallas')), vm_pool[1])
 def testDiskSpecs(self):
     s = """
 [{
     "ip_address": "174.12.14.1",
     "user_name": "ubuntu",
     "keyfile_path": "test_keyfile_path",
     "local_disks": ["/test_local_disk_0", "/test_local_disk_1"],
     "scratch_disk_mountpoints": ["/test_scratch_disk_0",
                                  "/test_scratch_disk_1"]
 }]
 """
     expected_paths_and_mount_points = ((None, '/test_scratch_disk_0'),
                                        (None, '/test_scratch_disk_1'),
                                        ('/test_local_disk_0', None),
                                        ('/test_local_disk_1', None))
     fp = StringIO(s)
     StaticVirtualMachine.ReadStaticVirtualMachineFile(fp)
     self.assertEqual(1, len(StaticVirtualMachine.vm_pool))
     vm = StaticVirtualMachine.GetStaticVirtualMachine()
     self.assertTrue(vm.from_pool)
     self.assertEqual(len(vm.disk_specs), 4)
     for disk_spec, expected_paths in zip(vm.disk_specs,
                                          expected_paths_and_mount_points):
         expected_device_path, expected_mount_point = expected_paths
         self.assertEqual(disk_spec.device_path, expected_device_path)
         self.assertEqual(disk_spec.mount_point, expected_mount_point)
Esempio n. 3
0
  def testReadFromFile_NoErr(self):
    s = ('[{'
         '  "ip_address": "174.12.14.1", '
         '  "user_name": "perfkitbenchmarker", '
         '  "keyfile_path": "perfkitbenchmarker.pem" '
         '}, '
         '{ '
         '   "ip_address": "174.12.14.121", '
         '   "user_name": "ubuntu", '
         '   "keyfile_path": "rackspace.pem", '
         '   "internal_ip": "10.10.10.2", '
         '   "zone": "rackspace_dallas" '
         '}] ')
    fp = BytesIO(s)
    StaticVirtualMachine.ReadStaticVirtualMachineFile(fp)

    vm_pool = StaticVirtualMachine.vm_pool
    self.assertEqual(2, len(vm_pool))
    self._AssertStaticVMsEqual(
        StaticVirtualMachine(
            '174.12.14.1', 'perfkitbenchmarker',
            'perfkitbenchmarker.pem'), vm_pool[0])
    self._AssertStaticVMsEqual(
        StaticVirtualMachine('174.12.14.121', 'ubuntu', 'rackspace.pem',
                             '10.10.10.2', 'rackspace_dallas'),
        vm_pool[1])
    def testReadFromFile_UnknownOsTypeDefaultsToLinuxRequiredKeys(self):
        FLAGS.os_type = 'unknown_os_type'
        s = ('[{'
             '  "ip_address": "174.12.14.1", '
             '  "user_name": "perfkitbenchmarker", '
             '  "keyfile_path": "perfkitbenchmarker.pem"'
             '}]')
        fp = StringIO(s)
        StaticVirtualMachine.ReadStaticVirtualMachineFile(fp)

        vm_pool = StaticVirtualMachine.vm_pool
        self.assertEqual(1, len(vm_pool))
        self._AssertStaticVMsEqual(
            StaticVirtualMachine(
                StaticVmSpec(_COMPONENT,
                             ip_address='174.12.14.1',
                             user_name='perfkitbenchmarker',
                             ssh_private_key='perfkitbenchmarker.pem')),
            vm_pool[0])
 def testCreateReturn(self):
     s = ('[{'
          '  "ip_address": "174.12.14.1", '
          '  "user_name": "perfkitbenchmarker", '
          '  "keyfile_path": "perfkitbenchmarker.pem" '
          '}, '
          '{ '
          '   "ip_address": "174.12.14.121", '
          '   "user_name": "ubuntu", '
          '   "keyfile_path": "rackspace.pem", '
          '   "internal_ip": "10.10.10.2", '
          '   "zone": "rackspace_dallas" '
          '}] ')
     fp = StringIO(s)
     StaticVirtualMachine.ReadStaticVirtualMachineFile(fp)
     self.assertEqual(2, len(StaticVirtualMachine.vm_pool))
     vm0 = StaticVirtualMachine.GetStaticVirtualMachine()
     self.assertTrue(vm0.from_pool)
     self.assertEqual(1, len(StaticVirtualMachine.vm_pool))
     vm0.Delete()
     self.assertEqual(2, len(StaticVirtualMachine.vm_pool))
     vm1 = StaticVirtualMachine.GetStaticVirtualMachine()
     self.assertIs(vm0, vm1)
 def testReadFromFile_Empty(self):
     fp = StringIO('[]')
     StaticVirtualMachine.ReadStaticVirtualMachineFile(fp)
     self.assertEqual([], list(StaticVirtualMachine.vm_pool))
Esempio n. 7
0
 def testReadFromFile_Empty(self):
   fp = BytesIO('[]')
   StaticVirtualMachine.ReadStaticVirtualMachineFile(fp)
   self.assertEqual([], StaticVirtualMachine.vm_pool)