Skip to content

Commit

Permalink
Merge branch 'dev' into TPT-2322/fixs-tags-in-instance-module
Browse files Browse the repository at this point in the history
  • Loading branch information
yec-akamai authored Jan 4, 2024
2 parents 1020992 + e98b960 commit 3205504
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/modules/account_availability_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Get info about a Linode Account Availability.

| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `region` | <center>`str`</center> | <center>Optional</center> | The Region of the Account Availability to resolve. |
| `region` | <center>`str`</center> | <center>**Required**</center> | The Region of the Account Availability to resolve. |

## Return Values

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/instance_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Get info about a Linode Instance.
| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `label` | <center>`str`</center> | <center>Optional</center> | The label of the Instance to resolve. |
| `id` | <center>`int`</center> | <center>Optional</center> | The ID of the Instance to resolve. |
| `label` | <center>`str`</center> | <center>Optional</center> | The label of the Instance to resolve. **(Conflicts With: `id`)** |
| `id` | <center>`int`</center> | <center>Optional</center> | The ID of the Instance to resolve. **(Conflicts With: `label`)** |

## Return Values

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/stackscript_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Get info about a Linode StackScript.
| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `label` | <center>`str`</center> | <center>Optional</center> | The label of the StackScript to resolve. |
| `id` | <center>`int`</center> | <center>Optional</center> | The ID of the StackScript to resolve. |
| `label` | <center>`str`</center> | <center>Optional</center> | The label of the StackScript to resolve. **(Conflicts With: `id`)** |
| `id` | <center>`int`</center> | <center>Optional</center> | The ID of the StackScript to resolve. **(Conflicts With: `label`)** |

## Return Values

Expand Down
2 changes: 1 addition & 1 deletion docs/modules/type_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Get info about a Linode Type.
| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `id` | <center>`str`</center> | <center>Optional</center> | The ID of the Type to resolve. |
| `id` | <center>`str`</center> | <center>**Required**</center> | The ID of the Type to resolve. |

## Return Values

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/vpc_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Get info about a Linode VPC.
| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `label` | <center>`str`</center> | <center>Optional</center> | The label of the VPC to resolve. |
| `id` | <center>`int`</center> | <center>Optional</center> | The ID of the VPC to resolve. |
| `label` | <center>`str`</center> | <center>Optional</center> | The label of the VPC to resolve. **(Conflicts With: `id`)** |
| `id` | <center>`int`</center> | <center>Optional</center> | The ID of the VPC to resolve. **(Conflicts With: `label`)** |

## Return Values

Expand Down
4 changes: 2 additions & 2 deletions docs/modules/vpc_subnet_info.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Get info about a Linode VPC Subnet.
| Field | Type | Required | Description |
|-----------|------|----------|------------------------------------------------------------------------------|
| `vpc_id` | <center>`int`</center> | <center>**Required**</center> | The ID of the VPC for this resource. |
| `label` | <center>`str`</center> | <center>Optional</center> | The label of the VPC Subnet to resolve. |
| `id` | <center>`int`</center> | <center>Optional</center> | The ID of the VPC Subnet to resolve. |
| `label` | <center>`str`</center> | <center>Optional</center> | The label of the VPC Subnet to resolve. **(Conflicts With: `id`)** |
| `id` | <center>`int`</center> | <center>Optional</center> | The ID of the VPC Subnet to resolve. **(Conflicts With: `label`)** |

## Return Values

Expand Down
4 changes: 4 additions & 0 deletions plugins/module_utils/linode_common_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def spec(self):
for attr in self.attributes:
options[attr.name] = SpecField(
type=attr.type,
required=len(self.attributes) == 1,
conflicts_with=[
v.name for v in self.attributes if v.name != attr.name
],
description=f"The {attr.display_name} of the "
f"{self.primary_result.display_name} to resolve.",
)
Expand Down
30 changes: 28 additions & 2 deletions tests/unit/module_utils/test_linode_common_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class TestLinodeInfoModule:

@pytest.fixture
@pytest.fixture(scope="function")
def mock_module(self):
return InfoModule(
primary_result=InfoModuleResult(
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_generate_spec(self, mock_module):

attr_field = spec.options.get("attr")
assert attr_field.type == FieldType.string
assert not attr_field.required
assert attr_field.required
assert attr_field.description == "The Attr of the Foo to resolve."

foo_result = spec.return_values.get("foo")
Expand All @@ -81,3 +81,29 @@ def test_generate_spec(self, mock_module):
assert bar_result.type == FieldType.dict
assert bar_result.sample == mock_module.secondary_results[0].samples

def test_generate_spec_multi_attr(self, mock_module):
"""
Ensures that multiple attributes are treated as conflicting.
"""
mock_module.attributes.append(
InfoModuleAttr(
name="attr_2",
display_name="Attr 2",
type=FieldType.string,
get=lambda *args: ["cool"]
)
)

spec = mock_module.spec

attr_field = spec.options.get("attr")
assert attr_field.type == FieldType.string
assert not attr_field.required
assert attr_field.conflicts_with == ["attr_2"]
assert attr_field.description == "The Attr of the Foo to resolve."

attr2_field = spec.options.get("attr_2")
assert attr2_field.type == FieldType.string
assert not attr2_field.required
assert attr2_field.conflicts_with == ["attr"]
assert attr2_field.description == "The Attr 2 of the Foo to resolve."

0 comments on commit 3205504

Please sign in to comment.