Example #1
0
    def test_build_publish_image_return_the_publish_image_created(self, mock_publish_vcenter):
        # given
        i = self.prepare_image()

        builder = {
            "displayName": "vcenter-vm-name",
            "esxHost": "esxhost_vcenter",
            "datastore": "datastore_vcenter",
            "network": "network_vcenter"
        }

        cred_account = uforge.CredAccountVSphere()

        publish_image = uforge.PublishImageVSphere()
        publish_image.displayName = builder["displayName"]
        publish_image.esxHost = builder["esxHost"]
        publish_image.datastore = builder["datastore"]
        publish_image.network = builder["network"]

        mock_publish_vcenter.return_value = publish_image

        # when
        publish_image_retrieved = i.build_publish_image(self.create_image("vcenter"), builder, cred_account)

        # then
        mock_publish_vcenter.assert_called_with(builder, cred_account)
        self.assertEqual(publish_image_retrieved.displayName, builder["displayName"])
        self.assertEqual(publish_image_retrieved.esxHost, builder["esxHost"])
        self.assertEqual(publish_image_retrieved.datastore, builder["datastore"])
        self.assertEqual(publish_image_retrieved.network, builder["network"])
Example #2
0
    def test_create_migration_create_a_migration_with_all_stages(self):
        # given
        m = migration.Migration()
        data = {"migration": {"name": "myMigrationTest", "os": "linux"}}
        target_format = self.create_targetFormat("nameTargetFormat")
        cred_account = uforge.CredAccountVSphere()
        install_profile = uforge.InstallProfile()
        image = uforge.Image()
        image.installProfile = install_profile
        publish_image = uforge.PublishImageVSphere()
        publish_image.credAccount = cred_account

        # when
        my_migration = m.create_migration(data["migration"]["name"],
                                          data["migration"]["os"],
                                          target_format.name, image,
                                          publish_image)

        # then
        self.assertEqual(my_migration.name, "myMigrationTest")
        self.assertEqual(my_migration.stages.stage[0].family,
                         data["migration"]["os"])
        self.assertEqual(my_migration.stages.stage[1].image.targetFormat.name,
                         target_format.name)
        self.assertEqual(my_migration.stages.stage[1].image.installProfile,
                         install_profile)
        self.assertEqual(
            my_migration.stages.stage[2].publishImage.targetFormat.name,
            target_format.name)
        self.assertEqual(my_migration.stages.stage[2].publishImage.credAccount,
                         cred_account)
Example #3
0
    def test_do_launch_succeed_when_all_parameters_are_ok(self, mock_rmtree, mock_out, mock_api_create, mock_upload_and_launch_migration_binary, mock_create_migration, mock_retrieve_account, mock_retrieve_publish_image, mock_retrieve_image, mock_retrieve_target_format, mock_retrieve_migration_configuration, mock_download_binary):
        # given
        m = migration.Migration()
        m.api = Api("url", username="******", password="******", headers=None,
                    disable_ssl_certificate_validation=False, timeout=constants.HTTP_TIMEOUT)
        m.login = "******"
        m.password = "******"

        mock_retrieve_migration_configuration.return_value = self.get_migration_config()
        mock_retrieve_target_format.return_value = self.create_targetFormat("targetFormatRetrieved")
        mock_retrieve_image.return_value = uforge.Image()
        mock_retrieve_publish_image.return_value = uforge.PublishImageVSphere()
        mock_retrieve_account.return_value = uforge.CredAccountVSphere()
        migration_to_create = uforge.migration()
        mock_create_migration.return_value = migration_to_create
        mock_upload_and_launch_migration_binary.return_value(0)

        # when
        m.do_launch("--file config.json")

        # then
        self.assertEquals(mock_api_create.call_count, 1)
        self.assertEquals(mock_download_binary.call_count, 1)
        self.assertEquals(mock_upload_and_launch_migration_binary.call_count, 1)
        self.assertEquals(mock_rmtree.call_count, 1)
        mock_out.assert_called_with("Migration launched successfully, please go to the platform to follow steps of the migration.", "OK")
Example #4
0
    def test_retrieve_account_from_platform_raise_exception_when_account_not_found(self, mock_api_get_all):
        # given
        api = Api("url", username="******", password="******", headers=None, disable_ssl_certificate_validation=False, timeout=constants.HTTP_TIMEOUT)
        cred_account = uforge.CredAccountVSphere()
        cred_account.name = "accountName"
        cred_account.uri = "/uri/credAccount"
        cred_accounts = self.create_accounts(cred_account, "vsphere")
        mock_api_get_all.return_value = cred_accounts

        # when
        with self.assertRaises(Exception) as e:
            migration_utils.retrieve_account(api, "login", "accountNotFound")

        # then
        self.assertTrue("CredAccount unknown: accountNotFound\n You can use the command 'hammr account create' to create an account." in e.exception)
Example #5
0
    def test_retrieve_account_return_the_cred_account_found(self, mock_api_get_all):
        # given
        api = Api("url", username="******", password="******", headers=None, disable_ssl_certificate_validation=False, timeout=constants.HTTP_TIMEOUT)
        cred_account = uforge.CredAccountVSphere()
        cred_account.name = "accountName"
        cred_account.uri = "/uri/credAccount"
        cred_accounts = self.create_accounts(cred_account, "vsphere")
        mock_api_get_all.return_value = cred_accounts

        # when
        cred_account_retrieved = migration_utils.retrieve_account(api, "login", cred_account.name)

        # then
        self.assertEqual(cred_account_retrieved.name, cred_account.name)
        self.assertEqual(cred_account_retrieved.uri, cred_account.uri)
Example #6
0
    def test_build_publish_image_raise_exception_when_format_name_not_found(
            self, mock_remove_special_chars):
        # given
        builder = {
            "displayName": "vcenter-vm-name",
            "esxHost": "esxhost_vcenter",
            "datastore": "datastore_vcenter",
            "network": "network_vcenter"
        }

        cred_account = uforge.CredAccountVSphere()

        mock_remove_special_chars.return_value = "vcenternotfound"

        # when
        with self.assertRaises(Exception) as e:
            migration_utils.build_publish_image(
                builder, self.create_target_format("vcenter"), cred_account)

        # then
        self.assertTrue(
            "TargetFormat type is unsupported: vcenter" in e.exception)