Ejemplo n.º 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_create_and_read_several_records(self):
        credentials1 = Credentials("username", "password", "domain")
        credentials_pickler.create(credentials1)

        credentials2 = Credentials("username", "password", None)
        credentials_pickler.create(credentials2)

        ret = credentials_pickler.read(credentials2)
        self.assertEqual(len(ret), 2)
    def test_delete(self):
        credentials1 = Credentials("user", "password", "domain1")
        credentials_pickler.create(credentials1)
        credentials2 = Credentials("user", "password", "domain2")
        credentials_pickler.create(credentials2)

        credentials_to_delete = Credentials("user", "password", None)
        credentials_pickler.delete(credentials_to_delete)
        self.assertEqual(credentials_pickler.read(credentials_to_delete), [])
 def test_update_one_record(self):
     credentials = Credentials("user", "qwerty", None)
     credentials_pickler.create(credentials)
     new_credentials = Credentials("user", "qwerty", "domain")
     credentials_pickler.update(credentials, new_credentials)
     ret = credentials_pickler.read(new_credentials)
     self.assertEqual(len(ret), 1)
     self.assertEqual(ret[0].username, "user")
     self.assertEqual(ret[0].password, "qwerty")
     self.assertEqual(ret[0].domain, "domain")
    def test_create_and_read_one_record(self):
        credentials1 = Credentials("username", "password", "domain")
        credentials_pickler.create(credentials1)

        credentials2 = Credentials("username", "password", None)
        credentials_pickler.create(credentials2)

        ret = credentials_pickler.read(credentials1)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0].username, "username")
        self.assertEqual(ret[0].password, "password")
        self.assertEqual(ret[0].domain, "domain")
Ejemplo n.º 6
0
    def test_create_and_read_several_records(self):
        credentials1 = Credentials("username", "password", "domain")
        migration_target1 = MigrationTarget(CloudType.Azure, credentials1,
                                            None)
        migration_target_pickler.create(migration_target1)

        credentials2 = Credentials("username", "password", None)
        migration_target2 = MigrationTarget(CloudType.Azure, credentials2,
                                            None)
        migration_target_pickler.create(migration_target2)

        ret = migration_target_pickler.read(migration_target2)
        self.assertEqual(len(ret), 2)
Ejemplo n.º 7
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()
Ejemplo n.º 8
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:\\")
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    def test_create_and_read_one_record(self):
        credentials = Credentials("username", "password", None)
        migration_target = MigrationTarget(CloudType.Azure, credentials, None)
        migration_target_pickler.create(migration_target)

        ret = migration_target_pickler.read(migration_target)
        self.assertEqual(ret[0].cloud_type, CloudType.Azure)
        self.assertEqual(ret[0].cloud_credentials.username, "username")
Ejemplo n.º 11
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_update_several_records(self):
        credentials1 = Credentials("user", "qwerty", "domain1")
        credentials_pickler.create(credentials1)

        credentials2 = Credentials("user", "qwerty", "domain2")
        credentials_pickler.create(credentials2)

        credentials3 = Credentials("user", "qwerty", "domain")
        credentials_to_update = Credentials("user", "qwerty", None)
        credentials_pickler.update(credentials_to_update, credentials3)
        ret = credentials_pickler.read(credentials_to_update)
        self.assertEqual(len(ret), 2)
        self.assertEqual(ret[0].username, "user")
        self.assertEqual(ret[0].password, "qwerty")
        self.assertEqual(ret[1].username, "user")
        self.assertEqual(ret[1].password, "qwerty")
        self.assertEqual(ret[0].domain, "domain")
        self.assertEqual(ret[1].domain, "domain")
 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), [])
Ejemplo n.º 14
0
    def test_update(self):
        credentials = Credentials("username", "password", None)
        migration_target = MigrationTarget(CloudType.Azure, credentials, None)
        migration_target_pickler.create(migration_target)

        new_migration_target = MigrationTarget(
            CloudType.AWS, migration_target.cloud_credentials, None)
        migration_target_pickler.update(migration_target, new_migration_target)
        ret = migration_target_pickler.read(new_migration_target)
        self.assertEqual(len(ret), 1)
        self.assertEqual(ret[0].cloud_type, CloudType.AWS)
    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)
Ejemplo n.º 16
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_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:\\")
Ejemplo n.º 19
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), [])
Ejemplo n.º 20
0
 def test_delete(self):
     credentials = Credentials("user", "pass", None)
     migration_target = MigrationTarget(CloudType.Azure, credentials, None)
     migration_target_pickler.create(migration_target)
     migration_target_pickler.delete(migration_target)
     self.assertEqual(migration_target_pickler.read(migration_target), [])