1
OpenStack Powershell CLI - Getting Set up to Contribute
5
Before we get started we need to make sure that our Development environment reflects what a machine looks like when we install the CLI. The following steps should get the job done.
7
A. Set the Required Execution Policy
9
To use the OpenStack CLI Software for Windows PowerShell, you must make sure that your Powershell environment is capable of executing 3rd party modules.
10
Note: If you are performing a re-installation of the software package, you can skip this step. This step is applicable only for a fresh installation.
11
Open a PowerShell window as the administrator and issue the command set-executionpolicy -ExecutionPolicy Unrestricted:
13
-------------------------------------------------------------------------------------------------------------------
14
PS C:\Projects\Outgoing\OS> set-executionpolicy -ExecutionPolicy Unrestricted
16
Execution policy change
18
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy
19
might expose you to the security risks described in the about_Execution_Policies help topic. Do you want to
20
change the execution policy?
21
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
22
PS C:\Projects\Outgoing\OS>
23
-------------------------------------------------------------------------------------------------------------------
24
Close the Powershell window and reopen as administrator for the policy changes to take effect.
26
B. A Quick Setting in Visual Studio
28
After Cloning the repo and loading the solution within Visual Studio, ensure that the "Enable Nuget Package Restore" option has been turned
29
on at the Solution level. This will retreive all of the neccessary external dependencies for the Solution to build properly.
31
C. - Supplying your Credentials
33
Our next step is to make sure that we supply the proper credentials when logging on to the system. If you ran the CLI after your initial
34
install, you'll have noticed that you were prompted for this information. The result is stored in the OpenStack.config file located within the Users Personal Data Folder
35
under the OS directory. With each Build we must update that file with the version in our solution. This is so that when new config file changes are introduced, you
36
have the CLI picking them up at runtime from the expected location (instead of residing in just your project directory). Complete these steps to supply this information.
38
1. Navigate to the OpenStack.Client.Powershell project and look into the Deployment folder.
39
2. Within that folder you will see a file called OpenStack.config.example
40
3. Copy the example file into the same folder but remove the .example on the filename.
41
4. Open up the OpenStack.config file that you just created.
42
5. Find the config section entitled "IdentityServices".
43
6. Within this section supply values for Username, Password, and Default Tenenat Id. All of this can be found within your account information on you providers portal.
45
Each time that we build, this OpenStack.config file will be moved to the correct runtime location via Post-Build Scripts outlined in the next section.
47
D. - Edit Post Build Scripts
49
Within the OpenStack.Client.Powershell projects Post-Build Event you'll notice that we call a PostBuild.bat file. This
50
batch file will move important run-time files required by the CLI to their proper locations if you decide to edit them.
51
Without this, all changes to important files (like OpenStack.config) would go unnoticed because they would sit in our project
52
folders on disk (rather than the location the CLI expects). To create tis batch file, follow these steps.
54
1. Navigate to the OpenStack.Client.Powershell project and look into the Deployment folder.
55
2. Within that folder you will see a file called PostBuild.example
56
3. Open up that file and copy the contents to the clipboard.
57
4. Within that same folder create a file called PostBuild.bat
58
5. Paste the script on the clipboard into that file.
59
6. Notice the Action Required section of the file. Modify the path you see there to reflect your development machine.
60
7. Save your Project and do a test build (Rebuild All). The Output Window will show any Echo results from the script and show any script errors that may break the build.
62
E. - Modifying you Developer Profile
64
When the Powershell runtime starts it looks for a file called Microsoft.PowerShell_profile.ps1. This script gets executed right after
65
Powershell loads. Here we can set up the look of the environment, issue some default commands (useful for testing!)
66
and loading Powershell Modules. The Powershell module is where all of our CLI code resides and must get loaded by this script.
67
The only problem here is that the path to that module is specific to your machine. To address this follow these steps
69
1. Open up the DevProfile.ps1.example file within the Solutions [OpenStack.Client.Powershell]\Deployment folder.
70
2. Copy the contents of this file into a new text file called DevProfile.ps1
71
3. Search this document for "ACTION REQUIRED" and follow the instructions given.
75
Debugging the CLI is a bit more challenging than with say a normal executable. In this case the entry point or main process is the Powershell runtime itself.
76
This requires us to load our work into that environment and attach the VS debugger to the Powershell host at runtime. Follow these steps to get the debugger running.
78
1. Set your breakpoint.
79
2. Compile the Solution.
80
3. Load Powershell. With everything in place this should automatically Import the module you just compiled.
81
3. From within VS select Debug\Attach To Process
82
4. Attach to the Powershell.exe process.
83
5. Issue a command in the CLI that triggers your breakpoint.
85
A. Debugging Provider Code
87
When Powershell modules get Imported, any providers found in that Module will be executed first. This leaves us with a problem in that
88
any code that we need to debug in the provider during startup needs to be paused until we have time to actually set a break point properly.
89
To do this complete the following actions.
91
1. Set you breakpoint in the providers InitializeDefaultDrives() method. This is the first stage in the Providers Life-Cycle.
92
2. Open the DevProfile.ps1 file.
93
3. Comment out the Import-Module statement (Copy it to the clipboard for your convience).
94
2. Compile the Solution.
96
3. From within VS select Debug\Attach To Process
97
4. Attach to the Powershell.exe process.
98
5. From the command line paste the Import-Module statement into the CLI. This will trigger the breakpoint that you set in step 1.
100
B. Getting to the Action - A Quick Tip
102
Sometimes we're trying to debug something in the CLI and we need to get to a certain location quickly. For example if you are testing the
103
list view for Servers and your sick of typing this after you restart each time
111
Just remember that this can be placed in your Devprofile.ps1 file and Powershell will issue those commands for you. This makes debugging a specific
112
section of the CLI much easier..
116
Object Storage Integration Test Notes
118
These unit test require a particular directory structure to be present on your machine to complete the test cases where we copy files and or folders to the server.
119
Make sure that you have something like the following on your machine.
121
Folder1 (contains files)
122
-> Folder2 (contains files)
123
-> Folder3 (contains NO files)
125
Note : Go to the Testing section in the OpenStack.config file. Make sure that LocalTestDirectory
126
element points to the root of the test folder hierarchy (Folder1 in the example above).
b'\\ No newline at end of file'