Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danischm committed Jun 30, 2023
1 parent 3a92113 commit 19d2887
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 69 deletions.
4 changes: 1 addition & 3 deletions docs/resources/device.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resource "nso_device" "example" {
port = 22
authgroup = "default"
admin_state = "locked"
cli_ned_id = "cisco-ios-cli-3.0:cisco-ios-cli-3.0"
cli_ned_id = "cisco-ios-cli-3.8:cisco-ios-cli-3.8"
}
```

Expand All @@ -37,8 +37,6 @@ resource "nso_device" "example" {
- Choices: `locked`, `unlocked`, `southbound-locked`, `config-locked`, `call-home`
- `authgroup` (String) The authentication credentials used when connecting to this managed device.
- `cli_ned_id` (String) CLI NED ID.
- `delete_mode` (String) Configure behavior when deleting/destroying the resource. Either delete the entire object (YANG container) being managed, or only delete the individual resource attributes configured explicitly and leave everything else as-is. Default value is `all`.
- Choices: `all`, `attributes`
- `instance` (String) An instance name from the provider configuration.
- `netconf_net_id` (String) NETCONF NED ID.
- `port` (Number) Port for the management interface on the device. If this leaf is not configured, NCS will use a default value based on the type of device. For example, a NETCONF device uses port 830, a CLI device over SSH uses port 22, and an SNMP device uses port 161.
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/device_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ resource "nso_device_config" "access_list" {
### Required

- `device` (String) An NSO device name.
- `path` (String) A RESTCONF path.

### Optional

- `attributes` (Map of String) Map of key-value pairs which represents the YANG leafs and its values.
- `delete` (Boolean) Delete object during destroy operation. Default value is `true`.
- `instance` (String) An instance name from the provider configuration.
- `lists` (Attributes List) YANG lists. (see [below for nested schema](#nestedatt--lists))
- `path` (String) A RESTCONF path.

### Read-Only

Expand Down
4 changes: 1 addition & 3 deletions docs/resources/device_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This resource can manage the Device Group configuration.
```terraform
resource "nso_device_group" "example" {
name = "test-group1"
device_names = ["c1"]
device_names = ["ce0"]
}
```

Expand All @@ -28,8 +28,6 @@ resource "nso_device_group" "example" {

### Optional

- `delete_mode` (String) Configure behavior when deleting/destroying the resource. Either delete the entire object (YANG container) being managed, or only delete the individual resource attributes configured explicitly and leave everything else as-is. Default value is `all`.
- Choices: `all`, `attributes`
- `device_groups` (List of String) A list of device groups.
- `device_names` (List of String) A list of device names.
- `instance` (String) An instance name from the provider configuration.
Expand Down
2 changes: 1 addition & 1 deletion examples/resources/nso_device/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ resource "nso_device" "example" {
port = 22
authgroup = "default"
admin_state = "locked"
cli_ned_id = "cisco-ios-cli-3.0:cisco-ios-cli-3.0"
cli_ned_id = "cisco-ios-cli-3.8:cisco-ios-cli-3.8"
}
2 changes: 1 addition & 1 deletion examples/resources/nso_device_group/resource.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
resource "nso_device_group" "example" {
name = "test-group1"
device_names = ["c1"]
device_names = ["ce0"]
}
3 changes: 2 additions & 1 deletion gen/definitions/device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ path: tailf-ncs:devices/device=%v
res_description: This resource can manage the Device configuration.
ds_description: This data source can read the Device configuration.
no_augment_config: true
no_delete_attributes: true
doc_category: Device
attributes:
- yang_name: name
Expand Down Expand Up @@ -54,4 +55,4 @@ attributes:
tf_name: cli_ned_id
type: String
description: CLI NED ID.
example: cisco-ios-cli-3.0:cisco-ios-cli-3.0
example: cisco-ios-cli-3.8:cisco-ios-cli-3.8
3 changes: 2 additions & 1 deletion gen/definitions/device_group.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ path: tailf-ncs:devices/device-group=%v
res_description: This resource can manage the Device Group configuration.
ds_description: This data source can read the Device Group configuration.
no_augment_config: true
no_delete_attributes: true
doc_category: Device
attributes:
- yang_name: name
Expand All @@ -16,7 +17,7 @@ attributes:
tf_name: device_names
type: StringList
description: A list of device names.
example: c1
example: ce0
- yang_name: device-group
tf_name: device_groups
type: StringList
Expand Down
4 changes: 2 additions & 2 deletions internal/provider/data_source_nso_device_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func (d *DeviceConfigDataSource) Read(ctx context.Context, req datasource.ReadRe
return
}

path := "tailf-ncs:devices/device=" + config.Instance.ValueString() + "/config"
path := "tailf-ncs:devices/device=" + config.Device.ValueString() + "/config"
if config.Path.ValueString() != "" {
path = "tailf-ncs:devices/device=" + config.Instance.ValueString() + "/config/" + config.Path.ValueString()
path = "tailf-ncs:devices/device=" + config.Device.ValueString() + "/config/" + config.Path.ValueString()
}

tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", path))
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/data_source_nso_device_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAccDataSourceNsoDeviceConfig(t *testing.T) {
{
Config: testAccDataSourceNsoDeviceConfigConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("data.nso_device_config.test", "id", "tailf-ncs:devices/device=c1/config"),
resource.TestCheckResourceAttr("data.nso_device_config.test", "id", "tailf-ncs:devices/device=ce0/config"),
resource.TestCheckResourceAttr("data.nso_device_config.test", "attributes.tailf-ned-cisco-ios:hostname", "R1"),
),
},
Expand All @@ -24,14 +24,14 @@ func TestAccDataSourceNsoDeviceConfig(t *testing.T) {

const testAccDataSourceNsoDeviceConfigConfig = `
resource "nso_device_config" "test" {
device = "c1"
device = "ce0"
attributes = {
"tailf-ned-cisco-ios:hostname" = "R1"
}
}
data "nso_device_config" "test" {
device = "c1"
device = "ce0"
depends_on = [nso_device_config.test]
}
`
5 changes: 2 additions & 3 deletions internal/provider/data_source_nso_device_group_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions internal/provider/data_source_nso_device_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion internal/provider/model_nso_device.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion internal/provider/model_nso_device_group.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions internal/provider/resource_nso_device.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/provider/resource_nso_device_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (r *DeviceConfigResource) Schema(ctx context.Context, req resource.SchemaRe
},
"path": schema.StringAttribute{
MarkdownDescription: "A RESTCONF path.",
Required: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplace(),
},
Expand Down Expand Up @@ -139,7 +139,7 @@ func (r *DeviceConfigResource) Create(ctx context.Context, req resource.CreateRe
return
}

plan.Id = plan.Path
plan.Id = types.StringValue(plan.getPath())

if plan.Attributes.IsUnknown() {
plan.Attributes = types.MapNull(types.StringType)
Expand Down
25 changes: 12 additions & 13 deletions internal/provider/resource_nso_device_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ func TestAccNsoDeviceConfig(t *testing.T) {
{
Config: testAccNsoDeviceConfigConfig_empty(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("nso_device_config.test", "id", "tailf-ncs:devices/device=c1/config"),
resource.TestCheckResourceAttr("nso_device_config.test", "id", "tailf-ncs:devices/device=ce0/config"),
),
},
{
Config: testAccNsoDeviceConfigConfig_hostname("R1"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("nso_device_config.test", "id", "tailf-ncs:devices/device=c1/config"),
resource.TestCheckResourceAttr("nso_device_config.test", "id", "tailf-ncs:devices/device=ce0/config"),
resource.TestCheckResourceAttr("nso_device_config.test", "attributes.tailf-ned-cisco-ios:hostname", "R1"),
),
},
{
ResourceName: "nso_device_config.test",
ImportState: true,
ImportStateId: "tailf-ncs:devices/device=c1/config",
ImportStateId: "tailf-ncs:devices/device=ce0/config",
},
{
Config: testAccNsoDeviceConfigConfig_hostname("R2"),
Expand All @@ -39,8 +39,8 @@ func TestAccNsoDeviceConfig(t *testing.T) {
{
Config: testAccNsoDeviceConfigConfig_nested(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("nso_device_config.nested", "lists.0.name", "rule"),
resource.TestCheckResourceAttr("nso_device_config.nested", "lists.0.items.0.seq", "10"),
resource.TestCheckResourceAttr("nso_device_config.nested", "lists.0.name", "std-access-list-rule"),
resource.TestCheckResourceAttr("nso_device_config.nested", "lists.0.items.0.rule", "permit ip any"),
),
},
},
Expand All @@ -50,15 +50,15 @@ func TestAccNsoDeviceConfig(t *testing.T) {
func testAccNsoDeviceConfigConfig_empty() string {
return `
resource "nso_device_config" "test" {
device = "c1"
device = "ce0"
}
`
}

func testAccNsoDeviceConfigConfig_hostname(hostname string) string {
return fmt.Sprintf(`
resource "nso_device_config" "test" {
device = "c1"
device = "ce0"
attributes = {
"tailf-ned-cisco-ios:hostname" = "%s"
}
Expand All @@ -69,18 +69,17 @@ func testAccNsoDeviceConfigConfig_hostname(hostname string) string {
func testAccNsoDeviceConfigConfig_nested() string {
return `
resource "nso_device_config" "nested" {
device = "c1"
path = "tailf-ned-cisco-ios:access-list/access-list=1"
device = "ce0"
path = "tailf-ned-cisco-ios:access-list/access-list-standard-range=1"
attributes = {
id = 1
listnumber = 1
}
lists = [
{
name = "rule"
key = "seq"
name = "std-access-list-rule"
key = "rule"
items = [
{
seq = 10
rule = "permit ip any"
}
]
Expand Down
14 changes: 0 additions & 14 deletions internal/provider/resource_nso_device_group.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/provider/resource_nso_device_group_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/provider/resource_nso_device_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19d2887

Please sign in to comment.