David Zeuthen | 107f249 | 2015-02-17 12:53:54 -0500 | [diff] [blame] | 1 | This file is intended for onboarding new SWEs hacking on buffet. |
| 2 | |
| 3 | A. Common workflows. |
| 4 | B. Registering your DUT. |
| 5 | |
| 6 | --- |
| 7 | A. COMMON WORKFLOWS |
| 8 | --- |
| 9 | |
Christopher Wiley | d318b27 | 2014-03-27 15:33:28 -0700 | [diff] [blame] | 10 | Some common workflows for developing with buffet: |
| 11 | |
| 12 | # Tell portage that you'd like to make local changes to Buffet: |
Vitaly Buka | 5da6596 | 2014-10-07 14:34:47 -0700 | [diff] [blame] | 13 | cros_workon start --board=${BOARD} buffet |
Christopher Wiley | d318b27 | 2014-03-27 15:33:28 -0700 | [diff] [blame] | 14 | |
| 15 | # Edit files in platform2/buffet/ |
| 16 | vim ... |
| 17 | |
| 18 | # Compile and install those changes into the chroot: |
Vitaly Buka | 5da6596 | 2014-10-07 14:34:47 -0700 | [diff] [blame] | 19 | USE=buffet emerge-${BOARD} buffet |
Christopher Wiley | d318b27 | 2014-03-27 15:33:28 -0700 | [diff] [blame] | 20 | |
| 21 | # Compile and run buffet unittests |
Vitaly Buka | 5da6596 | 2014-10-07 14:34:47 -0700 | [diff] [blame] | 22 | USE=buffet FEATURES=test emerge-${BOARD} buffet |
Christopher Wiley | d318b27 | 2014-03-27 15:33:28 -0700 | [diff] [blame] | 23 | |
| 24 | # Deploy the most recently built version of buffet to a DUT: |
Vitaly Buka | 5da6596 | 2014-10-07 14:34:47 -0700 | [diff] [blame] | 25 | cros deploy --board=${BOARD} <remote host> buffet |
Alex Vakulenko | 5298c2c | 2014-04-21 17:05:51 -0700 | [diff] [blame] | 26 | |
| 27 | #To enable additional debug logging in buffet daemon, run it as: |
| 28 | # buffet --v=<level>, where <level> is verbosity level of debug info: |
| 29 | # 1 - enable additional tracing of internal object construction and destruction |
| 30 | # 2 - add tracing of request and response data sent over HTTP (beware of |
| 31 | # privacy concerns). |
| 32 | # 3 - enable low-level CURL tracing for HTTP communication. |
| 33 | buffet --v=2 |
David Zeuthen | 107f249 | 2015-02-17 12:53:54 -0500 | [diff] [blame] | 34 | |
| 35 | --- |
| 36 | B. REGISTERING YOUR DUT |
| 37 | --- |
| 38 | |
| 39 | This process in described in great detail at |
| 40 | |
| 41 | https://developers.google.com/cloud-devices/v1/dev-guides/getting-started/register |
| 42 | |
| 43 | but since these instructions are generic and comprehensive, here's |
| 44 | exactly what you need to do to get started when working with |
| 45 | buffet/Brillo, in ten simple steps. |
| 46 | |
| 47 | The word DUT in this context is meant as the device that you want to |
| 48 | associate with the cloud - for most buffet/Brillo developers this will |
| 49 | be a Chromebook or another embedded device. These notes assume you |
| 50 | have shell access to the DUT and also have access to a normal Linux |
| 51 | workstation with shell and browser access. |
| 52 | |
| 53 | 1. Open an Incognito window in Chrome on your workstation, go to |
| 54 | https://www.google.com and log in with your test google account (NEVER |
| 55 | use @google.com credentials on DUTs). In the following we're using |
| 56 | <GMAIL_TEST_ACCOUNT> which you should replace with whatever you're |
| 57 | using, e.g. my-testing-account-xyz@gmail.com. |
| 58 | |
| 59 | 2. First we need an Authorization Code for the test user. This is |
| 60 | covered in more detail in |
| 61 | |
| 62 | https://developers.google.com/cloud-devices/v1/dev-guides/getting-started/authorizing#code |
| 63 | |
| 64 | but basically amounts to entering the following URL in the Incognito window |
| 65 | |
| 66 | https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/clouddevices&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=58855907228.apps.googleusercontent.com |
| 67 | |
| 68 | If you're not using the default buffet gcd-project, replace the |
| 69 | client_id parameter in the URL with the one for the product you |
| 70 | registered as per |
| 71 | |
| 72 | https://developers.google.com/cloud-devices/v1/dev-guides/getting-started/authorizing#setup |
| 73 | |
| 74 | 3. The browser window should display a prompt saying that |
| 75 | "clouddevicesclient" would like to "Manage your cloud device". Press |
| 76 | the "Accept" button and write down the Authorization Code |
| 77 | displayed. It should look something like this |
| 78 | |
| 79 | 4/J23qfSkXYFgF_0H7DCOtwS5O7HO69zF9LtnG9_ILIGA.QhJE9WLeqwcaJvIeHux6iLavlvowlwI |
| 80 | |
| 81 | 4. Open a bash prompt on your Linux workstation and type the following |
| 82 | |
| 83 | export SETUP_USER=<GMAIL_TEST_ACCOUNT> |
| 84 | export SETUP_CODE=4/J23qfSkXYFgF_0H7DCOtwS5O7HO69zF9LtnG9_ILIGA.QhJE9WLeqwcaJvIeHux6iLavlvowlwI |
| 85 | export SETUP_CLIENT_ID=58855907228.apps.googleusercontent.com |
| 86 | export SETUP_CLIENT_SECRET=eHSAREAHrIqPsHBxCE9zPPBi |
| 87 | |
| 88 | replacing the values for SETUP_USER and SETUP_CODE as |
| 89 | appropriate. Again, if you're not using the default buffet gcd-project |
| 90 | replace the values SETUP_CLIENT_ID and SETUP_CLIENT_SECRET as |
| 91 | appropriate. |
| 92 | |
| 93 | 5. Now we can get an Access Token. Run the following command from the shell: |
| 94 | |
| 95 | curl -d "code=${SETUP_CODE}&client_id=${SETUP_CLIENT_ID}&client_secret=${SETUP_CLIENT_SECRET}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token |
| 96 | |
| 97 | It should print out something like this: |
| 98 | |
| 99 | { |
| 100 | "access_token" : "ya29.HQE<...>", |
| 101 | "token_type" : "Bearer", |
| 102 | "expires_in" : 3600, |
| 103 | "refresh_token" : "1/iMq4<...>" |
| 104 | } |
| 105 | |
| 106 | 6. Export the access token in the shell: |
| 107 | |
| 108 | export SETUP_ACCESS_TOKEN=ya29.HQE<...> |
| 109 | |
| 110 | 7. Now we can get the Registration Ticket Id for the device. Run the following |
| 111 | |
| 112 | curl --header "Authorization: Bearer ${SETUP_ACCESS_TOKEN}" --header "Content-Type: application/json; charset=UTF-8" --data "{ \"userEmail\": \"${SETUP_USER}\" }" https://www.googleapis.com/clouddevices/v1/registrationTickets |
| 113 | |
| 114 | It should print out something like this |
| 115 | |
| 116 | { |
| 117 | "kind": "clouddevices#registrationTicket", |
| 118 | "id": "453f1139-bd<...>", |
| 119 | "deviceId": "77500a3f-458b-<...>", |
| 120 | "userEmail": "<GMAIL_TEST_ACCOUNT>", |
| 121 | "creationTimeMs": "1424193538212", |
| 122 | "expirationTimeMs": "1424193778212" |
| 123 | } |
| 124 | |
| 125 | 8. Now, open a shell on the DUT and export the following |
| 126 | |
| 127 | export DUT_SETUP_TICKET_ID=453f1139-bd<...> |
| 128 | |
| 129 | 9. Run the following command on the DUT shell |
| 130 | |
| 131 | buffet_client RegisterDevice ticket_id=${DUT_SETUP_TICKET_ID} |
| 132 | |
| 133 | appropriate. If you're not using the default buffet gcd-project you |
| 134 | also need to pass other parameters such as client_id, client_secret |
| 135 | and api_key. |
| 136 | |
| 137 | It should succeed and print the device-id |
| 138 | |
| 139 | Device registered: 77500a3f-458b-<...> |
| 140 | |
| 141 | 10. The registered DUT should now show up in the Google account that |
| 142 | you associated it with. In the Incognito window opened in step 1, go |
| 143 | to |
| 144 | |
| 145 | https://security.google.com/settings/security/permissions |
| 146 | |
| 147 | where you can e.g. revoke access to the device. |