UNPKG

9.38 kBMarkdownView Raw
1Different ways to debug azure-xplat-cli commands
2
3## Pre-requisites
4Ensure following things have been done, before debugging the commands or tests:
5* **Authentication**
6
7```
8* ARM Mode
9 azure login -u $username (organizational account) -p $password (token based)
10
11* ASM Mode
12 azure login -u $username (organizational account) -p $password (token based)
13 OR
14 azure account import $path-to-publish-settings-file (Cert based)
15```
16
17* **Setting the subscription**
18```
19* List all the subscriptions
20 azure account list
21* Set the subscription of your choice
22 azure account set "$Subscription Name"
23```
24
25## Using the -vv option
26This provides the underlying REST requests that take place upon executing the xplat cli command. It provides more insight into the actual REST request where the error happens.
27
28For example:
29```
30D:\sdk\xplat\azure-sdk-tools-xplat>azure site delete foozap1 -vv
31info: Executing command site delete
32verbose: Attempting to locate site foozap1
33verbose: Getting locations
34silly: Providers to register via registerResourceNamespace:
35silly: requestOptions
36silly: {
37silly: rawResponse: false,
38silly: queryString: {},
39silly: method: 'GET',
40silly: headers: { user-agent: 'WindowsAzureXplatCLI/0.8.16', x-ms-version: '2014-04-01' },
41silly: url: 'https://management.core.windows.net/06b24a43-b85a-c7t7-bd74-82f3429d998c/services/WebSpaces'
42silly: }
43silly: returnObject
44silly: {
45silly: statusCode: 200,
46silly: header: {
47silly: content-type: 'application/xml; charset=utf-8',
48silly: strict-transport-security: 'max-age=31536000; includeSubDomains',
49silly: content-length: '114',
50silly: x-ms-servedbyregion: 'ussouth2',
51silly: x-aspnet-version: '4.0.30319',
52silly: cache-control: 'private',
53silly: date: 'Wed, 18 Mar 2015 23:44:03 GMT',
54silly: x-powered-by: 'ASP.NET',
55silly: x-ms-request-id: 'c4fc8f157c76847fsda2f56732ce77a3',
56silly: server: '1.0.6198.202 (rd_rdfe_stable.150307-1902) Microsoft-HTTPAPI/2.0'
57silly: },
58silly: body: '<WebSpaces xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>'
59silly: }
60verbose: Getting sites
61verbose: []
62error: Unable to locate site named foozap1
63silly: {
64silly: arguments: undefined,
65silly: type: undefined,
66silly: message: 'Unable to locate site named foozap1',
67silly: __frame: {
68silly: name: 'lookupSiteNameAndWebSpace__20',
69silly: line: 871,
70silly: file: 'C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI\\lib\\commands\\asm\\websites\\websitesclient.js',
71silly: prev: {
72silly: name: '__8',
73silly: line: 661,
74silly: file: 'C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\CLI\\lib\\commands\\asm\\site.js',
75silly: prev: undefined,
76silly: calls: 1,
77silly: active: false,
78silly: offset: 14,
79silly: col: 15
80silly: },
81silly: calls: 2,
82silly: active: false,
83silly: offset: 12,
84silly: col: 9
85silly: },
86silly: rawStack: 'Error: Unable to locate site named foozap1
87info: Error information has been recorded to C:\Users\amzavery\.azure\azure.err
88verbose: Error: Unable to locate site named foozap1
89```
90
91## Using console.log()
92This is always handy and is guaranteed to work.
93It is a good practice to use util.inspect() to dump well formatted objects.
94In your script:
95```
96var util = require('util');
97. . .
98console.log(">>>>>>>>>>>>>> Some Identifier " + util.inspect(some_object, {depth: null}));
99. . .
100```
101Providing **{depth: null}** is optional. By default, it will dump object upto 3 levels deep. Setting depth to null will dump the complete object.
102
103## Using node inspector
104This will open a debugging session in a browser (chrome or opera). It is super easy to use.
105Steps to get it working:
106
107* ```npm install -g node-inspector```
108* Assuming this is being executing in the cmd prompt from the root directory of the cloned repo "azure-xplat-cli/"
109 * ```node-debug bin\azure group create -l "West US" testgroup1```
110* A browser (Chrome/Opera) should pop up, or it can be manually browsed at this url - http://127.0.0.1:8080/debug?port=5858
111* Now breakpoints can be set at desired location.
112* It may happen that files with extension "._js" are not seen initially in the left pane. Please set a break point anywhere in lib\cli.js and keep on pressing "F10". After some time, files with extension "_.js" can be seen. Breakpoints can now be set at desired line in "*._js" file.
113* A breakpoint can also be set in the underlying azure-sdk-for-node which has the management clients making the REST calls to the server.
114These can be seen inside the directories starting with name "azure" or "azure-*" inside the node_modules directory.
115(node_modules will be present after executing ```npm install``` from the root directory "azure-xplat-cli" of the cloned repo.)
116
117### For debugging tests:
118Please follow the below mentioned steps for the debugger to accept breakpoints set in your test file:
119* In the file azure-xplat-cli/scripts/unit.js
120```
121modify the last line
122from - require('../node_modules/mocha/bin/mocha');
123to - require('../node_modules/mocha/bin/_mocha');
124```
125* set a breakpoint at runTest() method of mocha's runner.
126In the file "azure-xplat-cli\node_modules\mocha\lib\runner.js" in the "runTest()" method around Line 378.
127 * **Note**: "node_modules" directory is not a part of "azure-xplat-cli" repository. If the **"node_modules"** directory or the **"mocha"** directory inside **"node_modules"** directory is not present, then ```npm install``` needs to be executed from the root directory of the cloned "azure-xplat-cli" repo.
128```
129Runner.prototype.runTest = function(fn){
130 var test = this.test
131 , self = this;
132
133 if (this.asyncOnly) test.asyncOnly = true;
134
135 try {
136 test.on('error', function(err){
137 self.fail(test, err);
138 });
139 test.run(fn); <<<<<<<<<<<<<<<<<<<<<<<-------- set a breakpoint here
140 } catch (err) {
141 fn(err);
142 }
143};
144```
145* Set a breakpoint in your test which should be located under "azure-xplat-cli/test/commands" directory
146
147
148## Using Visual Studio
149The Visual Studio plugin for node.js can be downloaded from [here](http://nodejstools.codeplex.com/).
150
151### Setting up the project
152* File --> New --> Project
153* On the left pane Installed --> Templates --> Javascript --> Node.js
154* From the available options Select "From Existing Node.js Code"
155 * Provide a name to your project "xplat" and a name to the solution "xplat"
156 * The location of the project would be the location of your cloned repo. Example - "D:\sdk\xplat\azure-sdk-tools-xplat"
157* Next --> Enter the filter to include files: In the end append the following string "; *._js"
158* Next --> Including node_modules in the project is optional. (It can always be include later, if the need arises).
159* Next --> Location for the project file - "D:\sdk\xplat\azure-sdk-tools-xplat\xplat.njsproj" --> Finish
160* In some time the solution explorer shows the source code files.
161* For better performance, it is advisable to **disable** intellisense in VisualStudio for Node.js projects by going to
162 * Tools --> Options --> TextEditor --> Node.js --> Intellisense -->No Intellisense.
163* Set the Tab size and Indentation to 2 spaces by going to
164 * Tools --> Options --> TextEditor --> Node.js --> Tabs --> [Tab size: 2, Indent size: 2]
165 * Tools --> Options --> TextEditor --> Javascript --> Tabs --> [Tab size: 2, Indent size: 2]
166
167### For debugging the commands:
168 * Right Click the "azure-xplat-cli\bin\azure.js" file and set it as Node.js startup file.
169 * From the menu bar go to Project --> Properties
170 * Script arguments should contain the command to execute - group list
171 * Save the changes.
172 * Set breakpoints at desired locations and Press F5 for happy debugging
173 * At times, files with extension "._js" do not hit the breakpoint. It is flaky and nothing can be done about it. At such times, console.log() is your best buddy :+1:
174
175### For debugging the tests:
176 * From the menu bar go to Project --> Properties and set the environment variables required for running tests.
177 * The list of environment variables can be found over [here](https://github.com/Azure/azure-xplat-cli/wiki/Setting-up-environment-variables-for-running-xplat-cli-tests)
178 * If the need arises to add a new environment variable for tests please update the [wiki](https://github.com/Azure/azure-xplat-cli/wiki/Setting-up-environment-variables-for-running-xplat-cli-tests) to keep the list current
179 * Visual Studio can also be opened from **"Visual Studio Debugger Cmd Prompt"** usually located at "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts\Developer Command Prompt for VS2013.lnk" to set the environment variables. Then open the .sln file from the prompt.
180 * In the Solution Explorer, click on a test that needs to be debugged. For example: "azure-xplat-cli\test\commands\cli.account.affinitygroup-tests.js"
181 * In the **Properties** pane select **"Mocha"** as the Test Framework. Save All the changes.
182 * The tests shall be seen in the "Test Explorer". Right Click on any Test and Select "Debug Selected Test".
\No newline at end of file