Skip to content

Commit

Permalink
Next available IP range calculator only considers active workspaces (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marrobi authored May 17, 2022
1 parent fad5dcb commit d7fd8db
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.27"
__version__ = "0.2.28"
9 changes: 7 additions & 2 deletions api_app/db/repositories/workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def workspaces_query_string():
def active_workspaces_query_string():
return f'SELECT * FROM c WHERE c.resourceType = "{ResourceType.Workspace}" AND {IS_ACTIVE_CLAUSE}'

def get_workspaces(self) -> List[Workspace]:
query = WorkspaceRepository.workspaces_query_string()
workspaces = self.query(query=query)
return parse_obj_as(List[Workspace], workspaces)

def get_active_workspaces(self) -> List[Workspace]:
query = WorkspaceRepository.active_workspaces_query_string()
workspaces = self.query(query=query)
Expand Down Expand Up @@ -107,11 +112,11 @@ def validate_address_space(self, address_space):
if (address_space is None):
raise InvalidInput("Missing 'address_space' from properties.")

allocated_networks = [x.properties["address_space"] for x in self.get_active_workspaces()]
allocated_networks = [x.properties["address_space"] for x in self.get_workspaces()]
return is_network_available(allocated_networks, address_space)

def get_new_address_space(self, cidr_netmask: int = 24):
networks = [x.properties["address_space"] for x in self.get_active_workspaces()]
networks = [x.properties["address_space"] for x in self.get_workspaces()]

new_address_space = generate_new_cidr(networks, cidr_netmask)
return new_address_space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def workspace():
return workspace


def test_get_workspaces_queries_db(workspace_repo):
workspace_repo.container.query_items = MagicMock()
expected_query = workspace_repo.workspaces_query_string()

workspace_repo.get_workspaces()
workspace_repo.container.query_items.assert_called_once_with(query=expected_query, enable_cross_partition_query=True)


def test_get_active_workspaces_queries_db(workspace_repo):
workspace_repo.container.query_items = MagicMock()
expected_query = workspace_repo.active_workspaces_query_string()
Expand Down
2 changes: 2 additions & 0 deletions devops/scripts/control_tre.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ if [[ $(az group list --output json --query "[?name=='rg-${TRE_ID}'] | length(@)
fi

az config set extension.use_dynamic_install=yes_without_prompt
az extension add --name azure-firewall
az --version

if [[ "$1" == *"start"* ]]; then
if [[ $(az network firewall list --output json --query "[?resourceGroup=='rg-${TRE_ID}'&&name=='fw-${TRE_ID}'] | length(@)") != 0 ]]; then
Expand Down

0 comments on commit d7fd8db

Please sign in to comment.