Exemplo n.º 1
0
        public static void AreEqualDeploymentSettings(ServiceSettings settings, string configPath, string deploymentName, string label, string packagePath, string subscriptionId, DeploymentSettings actual)
        {
            AreEqualServiceSettings(settings, actual.ServiceSettings);
            Assert.AreEqual<string>(configPath, actual.ConfigPath);
            Assert.AreEqual<string>(deploymentName, actual.DeploymentName);
            Assert.AreEqual<string>(label, actual.Label);
            Assert.AreEqual<string>(packagePath, actual.PackagePath);
            Assert.AreEqual<string>(subscriptionId, actual.SubscriptionId);

            Assert.IsTrue(File.Exists(actual.ConfigPath));
            Assert.IsTrue(File.Exists(actual.PackagePath));
        }
        public void TestDeploymentSettingsTestDoesNotConfigPathFail()
        {
            string label = "MyLabel";
            string deploymentName = service.ServiceName;
            string doesNotExistDir = Path.Combine(Directory.GetCurrentDirectory(), "qewindw443298.cscfg");

            try
            {
                DeploymentSettings deploySettings = new DeploymentSettings(settings, packagePath, doesNotExistDir, label, deploymentName);
                Assert.Fail("No exception was thrown");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(FileNotFoundException));
                Assert.AreEqual<string>(string.Format(Resources.PathDoesNotExistForElement, Resources.ServiceConfiguration, doesNotExistDir), ex.Message);
            }
        }
        /// <summary>
        /// Initialize our model of the AzureService located at the given
        /// path along with its DeploymentSettings and SubscriptionId.
        /// </summary>
        /// <param name="rootPath">Root path of the Azure service.</param>
        /// <param name="manifest">External runtime manifest to use, mainly for testing purposes</param>
        internal bool InitializeSettingsAndCreatePackage(string rootPath, string manifest = null)
        {
            Debug.Assert(!string.IsNullOrEmpty(rootPath), "rootPath cannot be null or empty.");
            Debug.Assert(Directory.Exists(rootPath), "rootPath does not exist.");

            _azureService = new AzureService(rootPath, null);

            // If user provided a service name, change current service name to use it.
            //
            if (!string.IsNullOrEmpty(ServiceName))
            {
                _azureService.ChangeServiceName(ServiceName, _azureService.Paths);
            }

            ServiceSettings defaultSettings = ServiceSettings.LoadDefault(
                _azureService.Paths.Settings,
                Slot,
                Location,
                AffinityGroup,
                Subscription,
                StorageAccountName,
                ServiceName,
                _azureService.ServiceName,
                out _hostedServiceName);

            if (!string.IsNullOrEmpty(defaultSettings.Subscription))
            {
                var globalComponents = GlobalComponents.Load(GlobalPathInfo.GlobalSettingsDirectory);
                CurrentSubscription = globalComponents.Subscriptions.Values.First(
                    subscription => subscription.SubscriptionName == defaultSettings.Subscription);
            }
            else
            {
                defaultSettings.Subscription = CurrentSubscription.SubscriptionName;
            }

            WriteVerboseWithTimestamp(String.Format(Resources.RuntimeDeploymentStart,
                _hostedServiceName));
            if (PrepareRuntimeDeploymentInfo(_azureService, defaultSettings, manifest))
            {

                WriteVerboseWithTimestamp(String.Format(Resources.PublishPreparingDeploymentMessage,
                    _hostedServiceName, CurrentSubscription.SubscriptionId));

                // Caching worker roles require update to their service configuration settings with
                // the storage service credentials. Before creating the package verify that the storage
                // service exists and fetch its credentials.
                if (!StorageAccountExists(defaultSettings.StorageAccountName))
                {
                    CreateStorageAccount(
                        defaultSettings.StorageAccountName,
                        _hostedServiceName,
                        defaultSettings.Location,
                        defaultSettings.AffinityGroup);
                }

                // Initiate call to all publish listeners.
                this._listeners.ForEach<IPublishListener>(l => l.OnPublish(Channel, _azureService, defaultSettings, CurrentSubscription.SubscriptionId));

                CreatePackage();

                _deploymentSettings = new DeploymentSettings(
                    defaultSettings,
                    _azureService.Paths.CloudPackage,
                    _azureService.Paths.CloudConfiguration,
                    _hostedServiceName,
                    string.Format(Resources.ServiceDeploymentName, defaultSettings.Slot));

                return true;
            }

            return false;
        }
Exemplo n.º 4
0
 public static void AreEqualDeploymentSettings(DeploymentSettings expected, DeploymentSettings actual)
 {
     AreEqualDeploymentSettings(expected.ServiceSettings, expected.ConfigPath, expected.DeploymentName, expected.Label, expected.PackagePath, expected.SubscriptionId, actual);
 }
        public void TestDeploymentSettingsTestWithFullServiceSettings()
        {
            string label = "MyLabel";
            string deploymentName = service.ServiceName;
            ServiceSettings fullSettings = ServiceSettingsTestData.Instance.Data[ServiceSettingsState.Sample1];
            DeploymentSettings deploySettings = new DeploymentSettings(fullSettings, packagePath, configPath, label, deploymentName);

            AzureAssert.AreEqualDeploymentSettings(fullSettings, configPath, deploymentName, label, packagePath, "f62b1e05-af8f-4205-8f98-325079adc155", deploySettings);
        }
        public void TestDeploymentSettingsTestWithDefaultServiceSettings()
        {
            string label = "MyLabel";
            string deploymentName = service.ServiceName;
            settings.Subscription = "TestSubscription2";
            DeploymentSettings deploySettings = new DeploymentSettings(settings, packagePath, configPath, label, deploymentName);

            AzureAssert.AreEqualDeploymentSettings(settings, configPath, deploymentName, label, packagePath, "f62b1e05-af8f-4205-8f98-325079adc155", deploySettings);
        }
        public void TestDeploymentSettingsTestNullSettingsFail()
        {
            string label = "MyLabel";
            string deploymentName = service.ServiceName;

            try
            {
                DeploymentSettings deploySettings = new DeploymentSettings(null, packagePath, configPath, label, deploymentName);
                Assert.Fail("No exception was thrown");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
                Assert.AreEqual<string>(Resources.InvalidServiceSettingMessage, ex.Message);
            }
        }
        public void TestDeploymentSettingsTestNullLabelFail()
        {
            string deploymentName = service.ServiceName;

            try
            {
                DeploymentSettings deploySettings = new DeploymentSettings(settings, packagePath, configPath, null, deploymentName);
                Assert.Fail("No exception was thrown");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
                Assert.IsTrue(string.Compare(string.Format(Resources.InvalidOrEmptyArgumentMessage, "Label"), ex.Message, true) == 0);
            }
        }