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

AV-95316 Removed deprecated resource ObjectAccessPolicy and added changes for CertificateManagementProfile test case #52

Merged
merged 1 commit into from
Oct 22, 2020
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
8 changes: 4 additions & 4 deletions avi/data_source_avi_analyticsprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAVIDataSourceAnalyticsProfileBasic(t *testing.T) {
resource.TestCheckResourceAttr(
"avi_analyticsprofile.testAnalyticsProfile", "apdex_response_threshold", "500"),
resource.TestCheckResourceAttr(
"avi_analyticsprofile.testAnalyticsProfile", "disable_se_analytics", "false"),
"avi_analyticsprofile.testAnalyticsProfile", "enable_se_analytics", "true"),
resource.TestCheckResourceAttr(
"avi_analyticsprofile.testAnalyticsProfile", "apdex_server_rtt_tolerated_factor", "4"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestAVIDataSourceAnalyticsProfileBasic(t *testing.T) {
resource.TestCheckResourceAttr(
"avi_analyticsprofile.testAnalyticsProfile", "apdex_server_response_tolerated_factor", "4"),
resource.TestCheckResourceAttr(
"avi_analyticsprofile.testAnalyticsProfile", "disable_server_analytics", "false"),
"avi_analyticsprofile.testAnalyticsProfile", "enable_server_analytics", "true"),
resource.TestCheckResourceAttr(
"avi_analyticsprofile.testAnalyticsProfile", "conn_server_lossy_timeo_rexmt_threshold", "20"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -149,7 +149,7 @@ resource "avi_analyticsprofile" "testAnalyticsProfile" {
tenant_ref = data.avi_tenant.default_tenant.id
hs_event_throttle_window = "1209600"
apdex_response_threshold = "500"
disable_se_analytics = false
enable_se_analytics = true
apdex_server_rtt_tolerated_factor = "4"
hs_security_nonpfs_penalty = "1"
hs_security_tls12_score = "5"
Expand All @@ -170,7 +170,7 @@ resource "avi_analyticsprofile" "testAnalyticsProfile" {
hs_security_tls11_score = "5"
exclude_gs_down_as_error = false
apdex_server_response_tolerated_factor = "4"
disable_server_analytics = false
enable_server_analytics = true
conn_server_lossy_timeo_rexmt_threshold = "20"
exclude_client_close_before_request_as_error = true
hs_security_weak_signature_algo_penalty = "1"
Expand Down
140 changes: 138 additions & 2 deletions avi/data_source_avi_certificatemanagementprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,148 @@ const testAccAVIDSCertificateManagementProfileConfig = `
data "avi_tenant" "default_tenant"{
name= "admin"
}
resource "avi_alertscriptconfig" "testAlertScriptConfig" {
name = "test-alertscriptconfig"
tenant_ref = data.avi_tenant.default_tenant.id
action_script = <<EOF
#!/usr/bin/python3
import os
import json
import sys
import time
from avi.sdk.avi_api import ApiSession
import urllib3
import requests

if hasattr(requests.packages.urllib3, 'disable_warnings'):
requests.packages.urllib3.disable_warnings()

if hasattr(urllib3, 'disable_warnings'):
urllib3.disable_warnings()


def ParseAviParams(argv):
if len(argv) != 2:
return
alert_params = json.loads(argv[1])
print(str(alert_params))
return alert_params


def get_api_token():
return os.environ.get('API_TOKEN')


def cleanup_old_spec_se(se_grp_uuid, session):
if not se_grp_uuid:
print('%s Empty SE Group UUID received' % time.ctime())
return

print('%s ===== CLEANUP OLD SPEC SE BEGIN =====' % time.ctime())

rsp = session.get('serviceenginegroup/%s' % se_grp_uuid)
if rsp.status_code != 200:
print('%s Service Engine Group %s not found' % (time.ctime(), se_grp_uuid))
se_grp_data = json.loads(rsp.content)
print(se_grp_data)
if 'instance_flavor' not in se_grp_data:
print('%s No flavor information found in the SE Group data, '
'nothing to do.' % (time.ctime()))
return

# Get all SE referring to this SE Group
rsp = session.get('serviceengine?page_size=1000'
'&refers_to=serviceenginegroup:%s' % se_grp_uuid)
if rsp.status_code != 200:
print('%s Service Engines could not be retrieved, status: %s' %
(time.ctime(), rsp.status_code))
se_dict = json.loads(rsp.content)['results']
old_spec_se = list()
for se_conf in se_dict:
if 'flavor' not in se_conf:
continue
if se_grp_data['instance_flavor'] != se_conf['flavor']:
old_spec_se.append(se_conf)

# Disable for placement all SE's using the older spec SE's
disabled_placement_old_spec_se = list()
for se_conf in old_spec_se:
se_conf['enable_state'] = 'SE_STATE_DISABLED_FOR_PLACEMENT'
rsp = session.put('serviceengine/%s/' % se_conf['uuid'], se_conf)
if rsp.status_code != 200:
print('%s Failed to disable for placement SE %s, status:%s, error:%s' %
(time.ctime(), se_conf['name'], rsp.status_code, rsp.content))
continue
disabled_placement_old_spec_se.append(se_conf)

# Then, Disable all SE's using the older spec SE's
disabled_old_spec_se = list()
for se_conf in disabled_placement_old_spec_se:
se_conf['enable_state'] = 'SE_STATE_DISABLED'
rsp = session.put('serviceengine/%s/' % se_conf['uuid'], se_conf)
if rsp.status_code != 200:
print('%s Failed to disable for placement SE %s, status:%s, error:%s' %
(time.ctime(), se_conf['name'], rsp.status_code, rsp.content))
continue
disabled_old_spec_se.append(se_conf)

# Wait for all SE to finish disabling
for se_conf in disabled_old_spec_se:
retry_count = 12
sleep_interval = 10
tries = 0
while True:
rsp = session.get('serviceengine/%s/runtime' % se_conf['uuid'])
if rsp.status_code != 200:
if rsp.status_code == 404:
print('%s SE %s no longer exists' % (time.ctime(), se_conf['name']))
break
print('%s Failed to fetch runtime for SE %s' %
(time.ctime(), se_conf['name']))
else:
se_runtime = json.loads(rsp.content)
if 'oper_status' in se_runtime and 'state' in se_runtime['oper_status']:
state = se_runtime['oper_status']['state']
if state != 'OPER_DISABLED':
print('%s SE %s not disabled yet, Oper state %s' %
(time.ctime(), se_conf['name'], state))
else:
print('%s SE %s has been disabled' %
(time.ctime(), se_conf['name']))
break
else:
print('%s Oper state not found for SE %s' %
(time.ctime(), se_conf['name']))
time.sleep(sleep_interval)
tries += 1
if tries > retry_count:
print('%s Giving up disabling SE %s after %d seconds, trying next SE' %
(time.ctime(), se_conf['name'], retry_count * sleep_interval))
break

print('%s ===== CLEANUP OLD SPEC SE DONE =====' % time.ctime())


if __name__ == "__main__":
alert_params = ParseAviParams(sys.argv)
se_grp_uuid = None
tenant_uuid = 'admin'
for event in alert_params.get('events', []):
if event['event_id'] == 'CONFIG_SE_GRP_FLAVOR_UPDATE':
se_grp_uuid = event['obj_uuid']
tenant_uuid = event['event_details']['config_se_grp_flv_update_details']['tenant_uuid']
token = get_api_token()
print('token = %s\n' % token)
with ApiSession('localhost', 'admin', token=token,
tenant_uuid=tenant_uuid) as session:
cleanup_old_spec_se(se_grp_uuid, session)
EOF
}
resource "avi_certificatemanagementprofile" "testCertificateManagementProfile" {
name = "test-cert-test-abc"
script_path = "test script path"
run_script_ref = avi_alertscriptconfig.testAlertScriptConfig.id
tenant_ref = data.avi_tenant.default_tenant.id
}

data "avi_certificatemanagementprofile" "testCertificateManagementProfile" {
name= "${avi_certificatemanagementprofile.testCertificateManagementProfile.name}"
}
Expand Down
8 changes: 8 additions & 0 deletions avi/datasource_avi_albservicesconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func dataSourceAviALBServicesConfig() *schema.Resource {
Computed: true,
Elem: ResourceIpReputationConfigSchema(),
},
"mode": {
Type: schema.TypeString,
Computed: true,
},
"polling_interval": {
Type: schema.TypeInt,
Computed: true,
Expand All @@ -48,6 +52,10 @@ func dataSourceAviALBServicesConfig() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"use_tls": {
Type: schema.TypeBool,
Computed: true,
},
"uuid": {
Type: schema.TypeString,
Optional: true,
Expand Down
17 changes: 11 additions & 6 deletions avi/datasource_avi_analyticsprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,27 @@ func dataSourceAviAnalyticsProfile() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"disable_ondemand_metrics": {
"enable_adaptive_config": {
Type: schema.TypeBool,
Computed: true,
},
"disable_se_analytics": {
"enable_advanced_analytics": {
Type: schema.TypeBool,
Computed: true,
},
"disable_server_analytics": {
"enable_ondemand_metrics": {
Type: schema.TypeBool,
Computed: true,
},
"disable_vs_analytics": {
"enable_se_analytics": {
Type: schema.TypeBool,
Computed: true,
},
"enable_adaptive_config": {
"enable_server_analytics": {
Type: schema.TypeBool,
Computed: true,
},
"enable_advanced_analytics": {
"enable_vs_analytics": {
Type: schema.TypeBool,
Computed: true,
},
Expand Down Expand Up @@ -311,6 +311,11 @@ func dataSourceAviAnalyticsProfile() *schema.Resource {
Type: schema.TypeFloat,
Computed: true,
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
5 changes: 5 additions & 0 deletions avi/datasource_avi_applicationpersistenceprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func dataSourceAviApplicationPersistenceProfile() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
5 changes: 5 additions & 0 deletions avi/datasource_avi_autoscalelaunchconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func dataSourceAviAutoScaleLaunchConfig() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"mesos": {
Type: schema.TypeSet,
Computed: true,
Expand Down
8 changes: 4 additions & 4 deletions avi/datasource_avi_certificatemanagementprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ func dataSourceAviCertificateManagementProfile() *schema.Resource {
Optional: true,
Computed: true,
},
"run_script_ref": {
Type: schema.TypeString,
Computed: true,
},
"script_params": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceCustomParamsSchema(),
},
"script_path": {
Type: schema.TypeString,
Computed: true,
},
"tenant_ref": {
Type: schema.TypeString,
Optional: true,
Expand Down
4 changes: 4 additions & 0 deletions avi/datasource_avi_controllerproperties.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ func dataSourceAviControllerProperties() *schema.Resource {
Type: schema.TypeInt,
Computed: true,
},
"max_threads_cc_vip_bg_worker": {
Type: schema.TypeInt,
Computed: true,
},
"permission_scoped_shared_admin_networks": {
Type: schema.TypeBool,
Computed: true,
Expand Down
5 changes: 5 additions & 0 deletions avi/datasource_avi_dnspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func dataSourceAviDnsPolicy() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
5 changes: 5 additions & 0 deletions avi/datasource_avi_errorpagebody.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func dataSourceAviErrorPageBody() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
5 changes: 5 additions & 0 deletions avi/datasource_avi_errorpageprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func dataSourceAviErrorPageProfile() *schema.Resource {
Computed: true,
Elem: ResourceErrorPageSchema(),
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
5 changes: 5 additions & 0 deletions avi/datasource_avi_gslbgeodbprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ func dataSourceAviGslbGeoDbProfile() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
5 changes: 5 additions & 0 deletions avi/datasource_avi_gslbservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func dataSourceAviGslbService() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"min_members": {
Type: schema.TypeInt,
Computed: true,
Expand Down
5 changes: 5 additions & 0 deletions avi/datasource_avi_hardwaresecuritymodulegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func dataSourceAviHardwareSecurityModuleGroup() *schema.Resource {
Computed: true,
Elem: ResourceHardwareSecurityModuleSchema(),
},
"labels": {
Type: schema.TypeList,
Computed: true,
Elem: ResourceKeyValueSchema(),
},
"name": {
Type: schema.TypeString,
Optional: true,
Expand Down
Loading