Exemple #1
0
    def test_normal_migration(self):
        selected = [MountPoint("C:\\", 1024), MountPoint("E:\\", 2048)]

        source_credentials = Credentials("username", "password", "domain")
        storage = [
            MountPoint("C:\\", 1024),
            MountPoint("E:\\", 2048),
            MountPoint("D:\\", 2048)
        ]
        source = Workload("127.0.0.1", source_credentials, storage)

        cloud_credentials = Credentials("username", "password", "cloud")
        target = MigrationTarget(CloudType.vSphere, cloud_credentials, None)

        migration = Migration(selected, source, target)
        migration.run()
        self.assertEqual(migration.migration_target.target_vm.ip, "127.0.0.1")
        self.assertEqual(
            migration.migration_target.target_vm.credentials.username,
            "username")
        self.assertEqual(
            migration.migration_target.target_vm.credentials.password,
            "password")
        self.assertEqual(
            migration.migration_target.target_vm.credentials.domain, "domain")
        self.assertEqual(
            [(s.mount_point_name, s.size)
             for s in migration.migration_target.target_vm.storage],
            [('C:\\', 1024), ('E:\\', 2048)])
        self.assertEqual(migration.migration_state, MigrationState.SUCCESS)
 def test_update(self):
     mount_point = MountPoint("E:\\", 4096)
     mount_point_pickler.create(mount_point)
     new_mount_point = MountPoint("E:\\", 2048)
     mount_point_pickler.update(mount_point, new_mount_point)
     ret = mount_point_pickler.read(new_mount_point)
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret[0].size, 2048)
Exemple #3
0
    def test_update_with_the_same_ip(self):
        credentials = Credentials("username", "password", "domain")
        workload = Workload("4.4.4.4", credentials, [MountPoint("C:\\", 1024)])

        workload_pickler.create(workload)
        with self.assertRaises(Exception):
            new_workload = Workload("4.4.4.4", credentials, [MountPoint("E:\\", 1024)])
            workload_pickler.update(workload, new_workload)
    def test_create_and_read_several_records(self):
        mount_point1 = MountPoint("C:\\", 1024)
        mount_point_pickler.create(mount_point1)

        mount_point2 = MountPoint("C:\\", None)
        mount_point_pickler.create(mount_point2)

        ret = mount_point_pickler.read(mount_point2)
        self.assertEqual(len(ret), 2)
Exemple #5
0
    def test_no_selected_storages_in_source(self):
        selected = [MountPoint("C:\\", 1024), MountPoint("E:\\", 2048)]

        source_credentials = Credentials("username", "password", "domain")
        storage = [MountPoint("D:\\", 2048), MountPoint("F:\\", 2048)]
        source = Workload("localhost", source_credentials, storage)

        cloud_credentials = Credentials("username", "password", "cloud")
        target = MigrationTarget(CloudType.vSphere, cloud_credentials, None)

        with self.assertRaises(Exception):
            migration = Migration(selected, source, target)
            migration.run()
    def test_update(self):
        credentials = Credentials("new_user", "password", None)
        migration_target = MigrationTarget(CloudType.Azure, credentials, None)
        workload = Workload("127.0.0.1", credentials, [])
        mount_points = [MountPoint("C:\\", 1024)]
        migration = Migration(mount_points, workload, migration_target)
        migration_pickler.create(migration)

        mount_points = [MountPoint("E:\\", 1024)]
        new_migration = Migration(mount_points, workload, migration_target)
        migration_pickler.update(migration, new_migration)
        ret = migration_pickler.read(new_migration)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0].mount_points[0].mount_point_name, "E:\\")
Exemple #7
0
    def test_update(self):
        credentials = Credentials("user", "qwerty", None)
        workload = Workload("8.8.8.8", credentials, [MountPoint("C:\\", 1024)])
        workload_pickler.create(workload)

        credentials = Credentials("new_user", "qwerty", None)
        new_workload = Workload("7.7.7.7", credentials, [MountPoint("C:\\", 1024)])
        workload_pickler.update(workload, new_workload)

        ret = workload_pickler.read(new_workload)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0].ip, "7.7.7.7")
        self.assertEqual(ret[0].credentials.username, "new_user")
        self.assertEqual(ret[0].storage[0].mount_point_name, "C:\\")
 def test_create_and_read_one_record(self):
     mount_point = MountPoint("C:\\", 1024)
     mount_point_pickler.create(mount_point)
     ret = mount_point_pickler.read(mount_point)
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret[0].mount_point_name, "C:\\")
     self.assertEqual(ret[0].size, 1024)
Exemple #9
0
 def test_create_and_read_one_record(self):
     credentials = Credentials("username", "password", "domain")
     workload = Workload("192.168.0.1", credentials, [MountPoint("C:\\", 1024)])
     workload_pickler.create(workload)
     ret = workload_pickler.read(workload)
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret[0].ip, "192.168.0.1")
     self.assertEqual(ret[0].credentials.username, "username")
     self.assertEqual(ret[0].storage[0].mount_point_name, "C:\\")
 def test_delete(self):
     credentials = Credentials("username", "new_password", None)
     migration_target = MigrationTarget(
         CloudType.AWS, credentials, Workload("127.0.0.1", credentials, []))
     workload = Workload("127.0.0.1", credentials, [])
     mount_points = [MountPoint("C:\\", 1024)]
     migration = Migration(mount_points, workload, migration_target)
     migration_pickler.create(migration)
     migration_pickler.delete(migration)
     self.assertEqual(migration_pickler.read(migration_target), [])
    def test_create_and_read_several_records(self):
        credentials1 = Credentials("username", "password", None)
        migration_target1 = MigrationTarget(
            CloudType.Azure, credentials1,
            Workload("127.0.0.1", credentials1, []))
        workload1 = Workload("127.0.0.1", credentials1, [])
        mount_points1 = [MountPoint("C:\\", 1024)]
        migration1 = Migration(mount_points1, workload1, migration_target1)
        migration_pickler.create(migration1)

        credentials2 = Credentials("username", "password", None)
        migration_target2 = MigrationTarget(CloudType.Azure, credentials2,
                                            None)
        workload2 = Workload("127.0.0.1", credentials2, [])
        mount_points2 = [MountPoint("C:\\", 1024)]
        migration2 = Migration(mount_points2, workload2, migration_target2)
        migration_pickler.create(migration2)

        ret = migration_pickler.read(migration2)
        self.assertEqual(len(ret), 2)
Exemple #12
0
    def test_json_enc(self):
        credentials = Credentials("username", "password", None)
        self.assertEqual(
            json.dumps(credentials.repr_json(), cls=ComplexEncoder),
            '{"username": "******", "password": "******", "domain": null}')

        mount_point = MountPoint('C:\\', 1024)
        self.assertEqual(
            json.dumps(mount_point.repr_json(), cls=ComplexEncoder),
            r'{"mount_point_name": "C:\\", "size": 1024}')

        workload = Workload("127.0.0.1", credentials, [mount_point])
        self.assertEqual(
            json.dumps(workload.repr_json(), cls=ComplexEncoder),
            '{"ip": "127.0.0.1", '
            '"credentials": {"username": "******", "password": "******", "domain": null}, '
            r'"storage": [{"mount_point_name": "C:\\", "size": 1024}]}')

        migration_target = MigrationTarget(CloudType.AWS, credentials,
                                           workload)
        self.assertEqual(
            json.dumps(migration_target.repr_json(), cls=ComplexEncoder),
            '{"cloud_type": "AWS", '
            '"cloud_credentials": {"username": "******", "password": "******", "domain": null}, '
            '"target_vm": {"ip": "127.0.0.1", "credentials":'
            ' {"username": "******", "password": "******", "domain": null}, '
            r'"storage": [{"mount_point_name": "C:\\", "size": 1024}]}}')

        migration = Migration([mount_point], workload, migration_target)
        self.assertEqual(
            json.dumps(migration.repr_json(), cls=ComplexEncoder),
            r'{"mount_points": [{"mount_point_name": "C:\\", "size": 1024}], '
            '"source": {"ip": "127.0.0.1", '
            '"credentials": {"username": "******", "password": "******", "domain": null}, '
            r'"storage": [{"mount_point_name": "C:\\", "size": 1024}]}, '
            '"migration_target": {"cloud_type": "AWS", '
            '"cloud_credentials": {"username": "******", "password": "******", "domain": null}, '
            '"target_vm": {"ip": "127.0.0.1", '
            '"credentials": {"username": "******", "password": "******", "domain": null}, '
            r'"storage": [{"mount_point_name": "C:\\", "size": 1024}]}}, '
            '"migration_state": "NOT_STARTED"}')
    def test_create_and_read(self):
        credentials = Credentials("username", "password", None)
        migration_target = MigrationTarget(CloudType.Azure, credentials, None)
        workload = Workload("127.0.0.1", credentials, [])
        mount_points = [MountPoint("C:\\", 1024)]
        migration = Migration(mount_points, workload, migration_target)
        migration_pickler.create(migration)

        ret = migration_pickler.read(migration)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0].migration_target.cloud_type, CloudType.Azure)
        self.assertEqual(ret[0].source.credentials.username, "username")
 def test_delete(self):
     mount_point = MountPoint("C:\\", 4096)
     mount_point_pickler.create(mount_point)
     mount_point_pickler.delete(mount_point)
     self.assertEqual(mount_point_pickler.read(mount_point), [])
Exemple #15
0
 def test_delete(self):
     credentials = Credentials("temp_user", "password", "domain")
     workload = Workload("3.3.3.3", credentials, [MountPoint("C:\\", 1024)])
     workload_pickler.create(workload)
     workload_pickler.delete(workload)
     self.assertEqual(workload_pickler.read(workload), [])