Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit agent name and tag scenarios #872

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions python-test/docs/agents/edit_agent_name_and_tags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Scenario: Edit agent name and tags
## Steps:
1 - Create an agent

- REST API Method: POST
- endpoint: /agents
- header: {authorization:token}

2- Edit this agent and tags

- REST API Method: PUT
- endpoint: /agents/agent_id
- header: {authorization:token}


## Expected Result:
- Request must have status code 200 (ok) and changes must be applied
71 changes: 37 additions & 34 deletions python-test/docs/development_guide.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions python-test/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
- [Remove agent using incorrect name](agents/remove_agent_using_incorrect_name.md)
- [Run two orb agents on the same port](agents/run_two_orb_agents_on_the_same_port.md)
- [Run two orb agents on different ports](agents/run_two_orb_agents_on_different_ports.md)
- [Edit agent name and tag](agents/edit_agent_name_and_tags.md)


## Agent Groups

Expand Down Expand Up @@ -149,6 +151,8 @@
- [Subscribe an agent to multiple groups created after agent provisioning](integration/subscribe_an_agent_to_multiple_groups_created_after_agent_provisioning.md)
- [Agent subscription to group after editing agent's tags](integration/agent_subscription_to_group_after_editing_agent's_tags.md)
- [Agent subscription to group with policies after editing agent's tags](integration/agent_subscription_to_group_with_policies_after_editing_agent's_tags.md)
- [Edit agent name and apply policies to then](integration/edit_agent_name_and_apply_policies_to_then.md)
- [Insert tags in agents created without tags and apply policies to group matching new tags.md](integration/insert_tags_in_agents_created_without_tags_and_apply_policies_to_group_matching_new_tags.md)

## Pktvisor Agent

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Scenario: Edit agent name and apply policies to then
Steps:
-
1. Provision an agent with tags
2. Create a group with same tags as agent
3. Create a sink
4. Create 1 policy
5. Create a dataset linking the group, the sink and the policy
8. Edit agent name

Expected result:
-
- Agent heartbeat must show just one group matching
- Agent logs must show that agent is subscribed to the group
- The container logs contain the message "policy applied successfully" referred to the policy applied to the second group
- The container logs that were output after all policies have been applied contains the message "scraped metrics for policy" referred to each applied policy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Scenario: Insert tags in agents created without tags and apply policies to group matching new tags
## Steps:
1. Provision an agent without tags
2. Create a group with tags
3. Create a sink
4. Create 1 policy
5. Create a dataset linking the group, the sink and the policy
8. Edit agent name and tags, using the same tag as the group

Expected result:
-
- Agent heartbeat must show just one group matching
- Agent logs must show that agent is subscribed to the group
- The container logs contain the message "policy applied successfully" referred to the policy applied to the second group
- The container logs that were output after all policies have been applied contains the message "scraped metrics for policy" referred to each applied policy
4 changes: 4 additions & 0 deletions python-test/docs/sanity.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
- [Remove agent using incorrect name](agents/remove_agent_using_incorrect_name.md)
- [Run two orb agents on the same port](agents/run_two_orb_agents_on_the_same_port.md)
- [Run two orb agents on different ports](agents/run_two_orb_agents_on_different_ports.md)
- [Edit agent name and tag](agents/edit_agent_name_and_tags.md)


## Agent Groups

Expand Down Expand Up @@ -127,3 +129,5 @@
- [Subscribe an agent to multiple groups created after agent provisioning](integration/subscribe_an_agent_to_multiple_groups_created_after_agent_provisioning.md)
- [Agent subscription to group after editing agent's tags](integration/agent_subscription_to_group_after_editing_agent's_tags.md)
- [Agent subscription to group with policies after editing agent's tags](integration/agent_subscription_to_group_with_policies_after_editing_agent's_tags.md)
- [Edit agent name and apply policies to then](integration/edit_agent_name_and_apply_policies_to_then.md)
- [Insert tags in agents created without tags and apply policies to group matching new tags.md](integration/insert_tags_in_agents_created_without_tags_and_apply_policies_to_group_matching_new_tags.md)
2 changes: 2 additions & 0 deletions python-test/docs/smoke.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,5 @@
- [Subscribe an agent to multiple groups created after agent provisioning](integration/subscribe_an_agent_to_multiple_groups_created_after_agent_provisioning.md)
- [Agent subscription to group after editing agent's tags](integration/agent_subscription_to_group_after_editing_agent's_tags.md)
- [Agent subscription to group with policies after editing agent's tags](integration/agent_subscription_to_group_with_policies_after_editing_agent's_tags.md)
- [Edit agent name and apply policies to then](integration/edit_agent_name_and_apply_policies_to_then.md)
- [Insert tags in agents created without tags and apply policies to group matching new tags.md](integration/insert_tags_in_agents_created_without_tags_and_apply_policies_to_group_matching_new_tags.md)
67 changes: 61 additions & 6 deletions python-test/features/agentsProvider.feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,72 @@ Feature: agent provider

Scenario: Provision agent without tags
Given the Orb user has a registered account
And the Orb user logs in
And the Orb user logs in
When a new agent is created with 0 orb tag(s)
And the agent container is started on port default
And the agent container is started on port default
Then the agent status in Orb should be online
And the container logs should contain the message "sending capabilities" within 10 seconds
And the container logs should contain the message "sending capabilities" within 10 seconds


Scenario: Provision agent with multiple tags
Given the Orb user has a registered account
And the Orb user logs in
And the Orb user logs in
When a new agent is created with 5 orb tag(s)
And the agent container is started on port default
And the agent container is started on port default
Then the agent status in Orb should be online
And the container logs should contain the message "sending capabilities" within 10 seconds
And the container logs should contain the message "sending capabilities" within 10 seconds


Scenario: Edit agent tag
Given the Orb user has a registered account
And the Orb user logs in
And a new agent is created with 5 orb tag(s)
And the agent container is started on port default
When edit the agent tags and use 3 orb tag(s)
Then the container logs should contain the message "sending capabilities" within 10 seconds
And agent must have 3 tags
And the agent status in Orb should be online


Scenario: Save agent without tag
Given the Orb user has a registered account
And the Orb user logs in
And a new agent is created with 5 orb tag(s)
And the agent container is started on port default
When edit the agent tags and use 0 orb tag(s)
Then the container logs should contain the message "sending capabilities" within 10 seconds
And agent must have 0 tags
And the agent status in Orb should be online


Scenario: Insert tags in agents created without tags
Given the Orb user has a registered account
And the Orb user logs in
And a new agent is created with 0 orb tag(s)
And the agent container is started on port default
When edit the agent tags and use 2 orb tag(s)
Then the container logs should contain the message "sending capabilities" within 10 seconds
And agent must have 2 tags
And the agent status in Orb should be online


Scenario: Edit agent name
Given the Orb user has a registered account
And the Orb user logs in
And a new agent is created with 1 orb tag(s)
And the agent container is started on port default
When edit the agent name
Then the container logs should contain the message "sending capabilities" within 10 seconds
And agent must have 1 tags
And the agent status in Orb should be online


Scenario: Edit agent name and tags
Given the Orb user has a registered account
And the Orb user logs in
And a new agent is created with 1 orb tag(s)
And the agent container is started on port default
When edit the agent name and edit agent tags using 3 orb tag(s)
Then the container logs should contain the message "sending capabilities" within 10 seconds
And agent must have 3 tags
And the agent status in Orb should be online
52 changes: 40 additions & 12 deletions python-test/features/integration.feature
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,46 @@ Scenario: Agent subscription to multiple group with policies after editing agent

Scenario: Agent subscription to group with policies after editing agent's tags (editing tags after agent provision)
Given the Orb user has a registered account
And the Orb user logs in
And that an agent with 1 orb tag(s) already exists and is online
And referred agent is subscribed to a group
And that a sink already exists
And 2 policies are applied to the group
And this agent's heartbeat shows that 2 policies are successfully applied
And an Agent Group is created with region:br orb tag(s)
And 1 policies are applied to the group
And the Orb user logs in
And that an agent with 1 orb tag(s) already exists and is online
And referred agent is subscribed to a group
And that a sink already exists
And 2 policies are applied to the group
And this agent's heartbeat shows that 2 policies are successfully applied
And an Agent Group is created with region:br orb tag(s)
And 1 policies are applied to the group
When edit the agent tags and use region:br orb tag(s)
Then the container logs contain the message "completed RPC subscription to group" referred to each matching group within 10 seconds
And this agent's heartbeat shows that 1 policies are successfully applied
And this agent's heartbeat shows that 1 groups are matching the agent
And the container logs contain the message "policy applied successfully" referred to each policy within 10 seconds
And the container logs that were output after all policies have been applied contain the message "scraped metrics for policy" referred to each applied policy within 180 seconds
And this agent's heartbeat shows that 1 policies are successfully applied
And this agent's heartbeat shows that 1 groups are matching the agent
And the container logs contain the message "policy applied successfully" referred to each policy within 10 seconds
And the container logs that were output after all policies have been applied contain the message "scraped metrics for policy" referred to each applied policy within 180 seconds


Scenario: Insert tags in agents created without tags and apply policies to group matching new tags
Given the Orb user has a registered account
And the Orb user logs in
And a new agent is created with 0 orb tag(s)
And the agent container is started on port default
And that a sink already exists
When edit the agent tags and use 2 orb tag(s)
And an Agent Group is created with same tag as the agent
And 1 policies are applied to the group
Then this agent's heartbeat shows that 1 policies are successfully applied
And the container logs contain the message "completed RPC subscription to group" referred to each matching group within 10 seconds
And this agent's heartbeat shows that 1 groups are matching the agent
And the container logs contain the message "policy applied successfully" referred to each policy within 10 seconds
And the container logs that were output after all policies have been applied contain the message "scraped metrics for policy" referred to each applied policy within 180 seconds


Scenario: Edit agent name and apply policies to then
Given the Orb user has a registered account
And the Orb user logs in
And that an agent with 5 orb tag(s) already exists and is online
And an Agent Group is created with same tag as the agent
And one agent must be matching on response field matching_agents
And that a sink already exists
And 1 policies are applied to the group
When edit the agent name and edit agent tags using 3 orb tag(s)
Then this agent's heartbeat shows that 1 policies are successfully applied
And the container logs contain the message "policy applied successfully" referred to each policy within 10 seconds
4 changes: 2 additions & 2 deletions python-test/features/steps/control_plane_agent_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
base_orb_url = configs.get('base_orb_url')


@when("an Agent Group is created with same tag as the agent")
@step("an Agent Group is created with same tag as the agent")
def create_agent_group_matching_agent(context):
agent_group_name = agent_group_name_prefix + random_string()
tags = context.agent["orb_tags"]
Expand Down Expand Up @@ -47,7 +47,7 @@ def error_response_message(context, message):
assert_that(response_value, equal_to(message), "Unexpected message for error")


@then("one agent must be matching on response field matching_agents")
@step("one agent must be matching on response field matching_agents")
def matching_agent(context):
matching_total_agents = context.agent_group_data['matching_agents']['total']
matching_online_agents = context.agent_group_data['matching_agents']['online']
Expand Down
26 changes: 25 additions & 1 deletion python-test/features/steps/control_plane_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,37 @@ def list_groups_matching_an_agent(context, amount_of_groups):


@step("edit the agent tags and use {orb_tags} orb tag(s)")
def editing_agent(context, orb_tags):
def editing_agent_tags(context, orb_tags):
agent = get_agent(context.token, context.agent["id"])
context.orb_tags = create_tags_set(orb_tags)
edit_agent(context.token, context.agent["id"], agent["name"], context.orb_tags, expected_status_code=200)
context.agent = get_agent(context.token, context.agent["id"])


@step("edit the agent name")
def editing_agent_name(context):
agent = get_agent(context.token, context.agent["id"])
agent_new_name = generate_random_string_with_predefined_prefix(agent_name_prefix, 5)
edit_agent(context.token, context.agent["id"], agent_new_name, agent['orb_tags'], expected_status_code=200)
context.agent = get_agent(context.token, context.agent["id"])
assert_that(context.agent["name"], equal_to(agent_new_name), "Agent name editing failed")


@step("edit the agent name and edit agent tags using {orb_tags} orb tag(s)")
def editing_agent_name_and_tags(context, orb_tags):
agent_new_name = generate_random_string_with_predefined_prefix(agent_name_prefix, 5)
context.orb_tags = create_tags_set(orb_tags)
edit_agent(context.token, context.agent["id"], agent_new_name, context.orb_tags, expected_status_code=200)
context.agent = get_agent(context.token, context.agent["id"])
assert_that(context.agent["name"], equal_to(agent_new_name), "Agent name editing failed")


@step("agent must have {amount_of_tags} tags")
def check_agent_tags(context, amount_of_tags):
agent = get_agent(context.token, context.agent["id"])
assert_that(len(dict(agent["orb_tags"])), equal_to(int(amount_of_tags)), "Amount of orb tags failed")


def expect_container_status(token, agent_id, status):
"""
Keeps fetching agent data from Orb control plane until it gets to
Expand Down
2 changes: 1 addition & 1 deletion python-test/features/steps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def insert_str(str_base, str_to_insert, index):
def generate_random_string_with_predefined_prefix(string_prefix, n_random=10):
"""
:param (str) string_prefix: prefix to identify object created by tests
:param (str) n_random: amount of random characters
:param (int) n_random: amount of random characters
:return: random_string_with_predefined_prefix
"""
random_string_with_predefined_prefix = string_prefix + random_string(n_random)
Expand Down
Loading