Skip to content

Commit f73323a

Browse files
feat: add diagnostic check to validate agent status, update integration tests
1 parent 42ca91a commit f73323a

22 files changed

+854
-590
lines changed

integration/README.md

Lines changed: 52 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
## Integration Tests
2-
1+
# Integration Tests
32

43
The root of this module location is intended to run integration tests using the terraform test framework. The tests are located at `integration/tests`
54

6-
The tests are run using the `terraform test -verbose` command from this folder `observe-agent/integration`
5+
The tests are run using the `terraform test -verbose` command from this folder `observe-agent/integration`
76

8-
When the above command is run, the tests in the `integration/tests` directory are ran using the variables provided. The tests are ran in the order of the run blocks provided in `<test>.tftest.hcl`
7+
When the above command is run, the tests in the `integration/tests` directory are ran using the variables provided. The tests are ran in the order of the run blocks provided in `<test>.tftest.hcl`
98

109
Generally a test will do the following for any given EC2 Machine:
10+
1111
- Create a machine using the variables provided below in `us-west-1`
12-
- Run a test using `observeinc/collection/aws//modules/testing/exec` module to accept python scripts located at `integration/tests/scripts`
12+
- Run a test using `observeinc/collection/aws//modules/testing/exec` module to accept python scripts located at `integration/tests/scripts`
1313

14-
### Pre-requisites
14+
## Pre-requisites
1515

16-
Ensure you have the following:
17-
- Built version of the agent ( in `observe-repos/observe-agent/dist`) using `go-releaser`
16+
Ensure you have the following:
17+
18+
- Built version of the agent ( in `observe-agent/dist`) using `go-releaser`
1819
- Blunderdome Admin Access in AWS (used to assume the `gh-observe_agent-repo` role for testing )
19-
- Observe Collection URL & Datastream Token to test with
20-
- Generated Private & public key pair ( name to `test_key.pub` & `test_key.pem`)
20+
- Observe Collection URL & Datastream Token to test with
21+
- Generated Private & public key pair ( name to `test_key.pub` & `test_key.pem`)
2122
- Terraform provider overide and terraform variables (see below section on how to do this)
2223

23-
2424
**Building the agent**:
2525

26-
```
26+
```sh
2727
observe-agent git:(nikhil/update-RM) ✗ goreleaser release --snapshot --clean --verbose
2828
```
2929

3030
If agent distributable is not built, you may get the following message:
3131

32-
```
32+
```txt
3333
│ Error: Test assertion failed
3434
3535
│ on tests/integration.tftest.hcl line 65, in run "test_install":
@@ -40,78 +40,69 @@ If agent distributable is not built, you may get the following message:
4040
│ Error in Installation Test
4141
```
4242

43-
44-
**SSH Key Pairs**:
43+
**SSH Key Pairs**:
4544

4645
Generate in PEM format for the OpenSSH Key that will be used by Terraform EC2 Modules:
4746

48-
```
47+
```sh
4948
ssh-keygen -m PEM
5049
```
5150

5251
For more info on generating SSH keys, see [here](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/create-key-pairs.html#how-to-generate-your-own-key-and-import-it-to-aws)
5352

54-
Ensure you have `./test_key.pub` and `./test_key.pem` in the `integration` directory. This can also be changed and specifed in the `integration/tests.auto.tfvars` file.
55-
56-
Ensure the extensions are correct!
53+
Ensure you have `./test_key.pub` and `./test_key.pem` in the `integration` directory. This can also be changed and specifed in the `integration/tests.auto.tfvars` file.
5754

55+
Ensure the extensions are correct!
5856

5957
**AWS UI Access (optional)**:
6058

61-
For AWS UI access for viewing machines:
62-
1. Login to Britive Blunderdome
59+
For AWS UI access for viewing machines:
6360

64-
2. Navigate to AWS Console
61+
1. Login to Britive Blunderdome
6562

66-
<p align="left">
67-
<img src="screenshots/aws-console.png" alt="AWS Console" width="300"/>
68-
</p>
63+
2. Navigate to AWS Console
6964

70-
3. Click Switch role and input details for `nikhil-ps-account` which is the member account for integration testing within Blunderdome. Details are the following:
71-
<p align="left">
72-
<img src="screenshots/member-account.png" alt="Member Account" width="500"/>
73-
</p>
65+
![AWS Console](screenshots/aws-console.png)
7466

75-
4. You can now access EC2 machines and download key pairs (same as what Github Actions workflow uses)
67+
3. Click Switch role and input details for `nikhil-ps-account` which is the member account for integration testing within Blunderdome. Details are the following:
7668

77-
5. Ensure you're in `us-west-1`
69+
![Member Account](screenshots/member-account.png)
7870

71+
4. You can now access EC2 machines and download key pairs (same as what Github Actions workflow uses)
7972

73+
5. Ensure you're in `us-west-1`
8074

81-
### Terraform Variables
75+
## Terraform Variables
8276

83-
The tests are run using the following variables. These can be set in the `integration/tests.auto.tfvars` file for local testing.
77+
The tests are run using the following variables. These can be set in the `integration/tests.auto.tfvars` file for local testing.
8478

85-
```
86-
name_format = "tf-observe-agent-test-%s"
87-
AWS_MACHINE= "AMAZON_LINUX_2023" #Choose the AWS Machine to run the tests on
79+
```terraform
80+
name_format = "tf-observe-agent-test-%s"
81+
AWS_MACHINE = "AMAZON_LINUX_2023" #Choose the AWS Machine to run the tests on
8882
PUBLIC_KEY_PATH = "./test_key.pub" #Path to Public Key for EC2
8983
PRIVATE_KEY_PATH = "./test_key.pem" #Path to Private Key for EC2
90-
OBSERVE_URL = "https://<TENANT_ID.collect.observe-staging.com>" #Observe URL to use for testing
91-
OBSERVE_TOKEN ="<DATASTREAM_TOKEN_TO_TEST_OBSERVE_AGENT_WITH">
92-
```
84+
OBSERVE_URL = "https://<TENANT_ID.collect.observe-staging.com>" #Observe URL to use for testing
85+
OBSERVE_TOKEN = "<DATASTREAM_TOKEN_TO_TEST_OBSERVE_AGENT_WITH">
86+
```
9387

94-
The PUBLIC & PRIVATE key pair can be generated by following the instructions in the "SSH Key Pairs" section above
88+
The PUBLIC & PRIVATE key pair can be generated by following the instructions in the "SSH Key Pairs" section above
9589

9690
Example of what the `integrations` folder contains after creating `.*tfvars` file and SSH Key Pair:
9791

92+
![SSH Example](screenshots/ssh-example.png)]
9893

99-
<p align="left">
100-
<img src="screenshots/ssh-example.png" alt="SSH Example" width="200"/>
101-
</p>
102-
103-
104-
### Terraform Provider
94+
## Terraform Provider
10595

10696
Note: You must also set the provider correctly. We use the following settings:
97+
10798
- Region: `us-west-1`
10899
- Profile: `blunderdome`
109-
- IAM Role Assumed: `gh-observe_agent-repo`
100+
- IAM Role Assumed: `gh-observe_agent-repo`
110101
- The above role has permissions to create and destroy EC2 instances. See `modules/setup_aws_backend/role.tf` for more details.
111102

112103
The provider can be directly set in the `integration/tests/integration.tftest.hcl` as below:
113104

114-
```
105+
```terraform
115106
provider "aws" {
116107
region = "us-west-1" # Specify the AWS region
117108
profile = "blunderdome"
@@ -126,34 +117,28 @@ or through a `provider_override.tf` placed in `modules/create_ec2` directory.
126117

127118
Example of this:
128119

129-
<p align="left">
130-
<img src="screenshots/provider-example.png" alt="SSH Example" width="200"/>
131-
</p>
132-
133-
134-
120+
![Provider Example](screenshots/provider-example.png)
135121

136122
> [!NOTE]
137-
> For Terraform to access and assume the role properly, you MUST be logged into Blunderdome Admin in console and have the correct permissions!
123+
> For Terraform to access and assume the role properly, you MUST be logged into Blunderdome Admin in console and have the correct permissions!
138124
139125
Example of this:
140126

141-
```
127+
```sh
142128
observe git:(master) ✗ s/aws-creds checkout blunderdome
143129

144130
Checked out 'AWS Blunderdome Organization/460044344528 (observe-blunderdome)/BritiveBlunderdome-FullAWSAdmin' into awscli profile 'blunderdome'
145131

146132
observe git:(master) ✗ export AWS_PROFILE=blunderdome
147133
```
148134

149-
150-
### Local Testing (without terraform test)
135+
## Local Testing (without terraform test)
151136

152137
Any of the python scripts in the `/scripts` directory can be tested by running them directly, granted an EC2 Machine exists. As the scripts rely on the outputs of `create_ec2` and `setup_observe_variables` modules to be passed in as environment variables, these environment variables can be manually set if the set up modules are not ran.
153138

154-
The `/scripts/<test_xyz.py` expects the following environment variables to be set:
139+
The `/scripts/<test_xyz>.py` expects the following environment variables to be set:
155140

156-
```
141+
```sh
157142
HOST="54.177.249.99" #HOST IP Address
158143
USER="ubuntu" #HOST user to login as
159144
KEY_FILENAME="./test_key.pem" #Private path to key
@@ -162,19 +147,20 @@ MACHINE_CONFIG="ami_description:Ubuntu Server 22.04 LTS (HVM)- EBS General Purpo
162147
OBSERVE_URL="" #Observe URL to use for testing
163148
OBSERVE_TOKEN="" #Observe Token to use for testing
164149
PASSWORD="WindowsPassword to be used for testing" # Set to None for testing
165-
166150
```
167151

168152
Run the scripts from the folder as below:
169-
```
153+
154+
```sh
170155
➜ integration git:(nikhil/integration-testing-windows) ✗ pwd
171156
/Users/nikhil.dua/Documents/observe-repos/observe-agent/integration
172-
➜ integration git:(nikhil/integration-testing-windows) ✗ python3 scripts/test_installation.py
157+
➜ integration git:(nikhil/integration-testing-windows) ✗ python3 scripts/test_install.py
173158
```
174159

175-
Note: If testing Windows machines, the RDP password is redacted by default in the python scripts.
160+
Note: If testing Windows machines, the RDP password is redacted by default in the python scripts.
176161
This can be turned off when disabling mask by setting below environment variable to `False` before running these scripts
177-
```
162+
163+
```sh
178164
export MASK=False
179165
python3 scripts/test_ec2_connection.py
180166
------------------------------
@@ -185,9 +171,6 @@ Env vars set to:
185171
Testing SSH connection to host 54.177.26.178 with timeout 120s
186172
```
187173

188-
### Architecture
174+
## Architecture
189175

190176
The architecture diagram can be found ![here](screenshots/Observe-Agent.png)
191-
192-
193-

0 commit comments

Comments
 (0)