diff --git a/test/integration/fixtures/TestInstance_AlertsWorkflow.yaml b/test/integration/fixtures/TestInstance_AlertsWorkflow.yaml new file mode 100644 index 000000000..0bcae76ca --- /dev/null +++ b/test/integration/fixtures/TestInstance_AlertsWorkflow.yaml @@ -0,0 +1,961 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/v4beta/regions?page=1 + method: GET + response: + body: '{"data": [{"id": "pl-labkrk-2", "label": "Krakow, PL", "country": "pl", + "capabilities": ["Linodes", "Block Storage Encryption", "Disk Encryption", "Backups", + "NodeBalancers", "Block Storage", "Object Storage", "GPU Linodes", "Kubernetes", + "Cloud Firewall", "Vlans", "VPCs", "VPC Dual Stack", "VPC IPv6 Stack", "Block + Storage Migrations", "Managed Databases", "Metadata", "Premium Plans", "Placement + Group", "StackScripts", "NETINT Quadra T1U", "Maintenance Policy", "Linode Interfaces", + "ACLP Logs Datacenter LKE-E"], "monitors": {"alerts": ["Linodes", "Managed Databases", + "NodeBalancers", "logs"], "metrics": ["Linodes", "Managed Databases", "NodeBalancers", + "logs"]}, "status": "ok", "resolvers": {"ipv4": "172.24.224.240,172.24.224.229,172.24.224.236,172.24.224.238,172.24.224.235,172.24.224.241,172.24.224.230,172.24.224.239,172.24.224.233,172.24.224.234", + "ipv6": "1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678"}, + "placement_group_limits": {"maximum_pgs_per_customer": null, "maximum_linodes_per_pg": + 5, "maximum_linodes_per_flexible_pg": 5}, "site_type": "core"}], "page": 1, + "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=900 + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - '*' + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"region":"pl-labkrk-2","type":"g6-nanode-1","label":"go-test-ins-s56i25fzcj55","root_pass":"5302.l8?K3`eqIS\u003eldK(zEcy~aJLGq[\u003c.KUP$:\u003e6rX\u003c!U7357yc|92?t1Qe3w8BS","image":"linode/debian12","booted":false}' + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/v4beta/linode/instances + method: POST + response: + body: '{"id": 101246022, "label": "go-test-ins-s56i25fzcj55", "group": "", "status": + "provisioning", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", + "type": "g6-nanode-1", "ipv4": ["172.24.237.136"], "ipv6": "1234::5678/128", + "image": "linode/debian12", "region": "pl-labkrk-2", "site_type": "core", "specs": + {"disk": 25600, "memory": 1024, "vcpus": 1, "gpus": 0, "transfer": 1000, "accelerated_devices": + 0}, "alerts": {"cpu": 90, "network_in": 10, "network_out": 10, "transfer_quota": + 80, "io": 10000, "system_alerts": [], "user_alerts": []}, "backups": {"enabled": + false, "available": false, "schedule": {"day": null, "window": null}, "last_successful": + null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": [], "host_uuid": + "69fd29fea98850c841cf2d4f21dd53bed8b6752a", "has_user_data": false, "placement_group": + null, "disk_encryption": "enabled", "lke_cluster_id": null, "capabilities": + ["Block Storage Encryption", "SMTP Enabled", "Maintenance Policy"], "interface_generation": + "legacy_config", "maintenance_policy": "linode/migrate", "locks": []}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "8" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_create","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode"}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123293, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 53, "time_remaining": null, "rate": null, + "duration": 16.56847, "action": "linode_create", "username": "psnoch", "entity": + {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", "url": + "/v4/linode/instances/101246022"}, "status": "started", "secondary_entity": + {"id": "linode/debian12", "type": "image", "label": "Debian 12", "url": "/v4/images/linode/debian12"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "561" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_create","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode","id":{"+gte":37123293}}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123293, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 100, "time_remaining": null, "rate": null, + "duration": 30.0, "action": "linode_create", "username": "psnoch", "entity": + {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", "url": + "/v4/linode/instances/101246022"}, "status": "finished", "secondary_entity": + {"id": "linode/debian12", "type": "image", "label": "Debian 12", "url": "/v4/images/linode/debian12"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "559" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"go-test-ins-s56i25fzcj55","alerts":{"cpu":50,"io":6000,"network_in":20,"network_out":20,"transfer_quota":50},"watchdog_enabled":true,"tags":[],"group":"","maintenance_policy":"linode/migrate"}' + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/v4beta/linode/instances/101246022 + method: PUT + response: + body: '{"id": 101246022, "label": "go-test-ins-s56i25fzcj55", "group": "", "status": + "offline", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", + "type": "g6-nanode-1", "ipv4": ["172.24.237.136"], "ipv6": "1234::5678/128", + "image": "linode/debian12", "region": "pl-labkrk-2", "site_type": "core", "specs": + {"disk": 25600, "memory": 1024, "vcpus": 1, "gpus": 0, "transfer": 1000, "accelerated_devices": + 0}, "alerts": {"cpu": 50, "network_in": 20, "network_out": 20, "transfer_quota": + 50, "io": 6000, "system_alerts": [], "user_alerts": []}, "backups": {"enabled": + false, "available": false, "schedule": {"day": null, "window": null}, "last_successful": + null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": [], "host_uuid": + "69fd29fea98850c841cf2d4f21dd53bed8b6752a", "has_user_data": false, "placement_group": + null, "disk_encryption": "enabled", "lke_cluster_id": null, "capabilities": + ["Block Storage Encryption", "SMTP Enabled", "Maintenance Policy"], "interface_generation": + "legacy_config", "maintenance_policy": "linode/migrate", "locks": []}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"region":"pl-labkrk-2","type":"g6-nanode-1","backups_enabled":false,"alerts":{}}' + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/v4beta/linode/instances/101246022/clone + method: POST + response: + body: '{"id": 101246026, "label": "linode101246026", "group": "", "status": "offline", + "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "type": + "g6-nanode-1", "ipv4": ["172.24.244.208"], "ipv6": "1234::5678/128", + "image": "linode/debian12", "region": "pl-labkrk-2", "site_type": "core", "specs": + {"disk": 25600, "memory": 1024, "vcpus": 1, "gpus": 0, "transfer": 1000, "accelerated_devices": + 0}, "alerts": {"cpu": 90, "network_in": 10, "network_out": 10, "transfer_quota": + 80, "io": 10000, "system_alerts": [], "user_alerts": []}, "backups": {"enabled": + false, "available": false, "schedule": {"day": null, "window": null}, "last_successful": + null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": [], "host_uuid": + "e7dbe65d12caf5c1a1de6dc8a495aeb8cc383445", "has_user_data": false, "placement_group": + null, "disk_encryption": "enabled", "lke_cluster_id": null, "capabilities": + ["Block Storage Encryption", "SMTP Enabled", "Maintenance Policy"], "interface_generation": + "legacy_config", "maintenance_policy": "linode/migrate", "locks": []}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "8" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_clone","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode"}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123330, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 33, "time_remaining": null, "rate": null, + "duration": 16.012781, "action": "linode_clone", "username": "psnoch", "entity": + {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", "url": + "/v4/linode/instances/101246022"}, "status": "started", "secondary_entity": + {"id": 101246026, "type": "linode", "label": "linode101246026", "url": "/v4/linode/instances/101246026"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "564" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_clone","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode","id":{"+gte":37123330}}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123330, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 35, "time_remaining": "0:1:27", "rate": "283.00 + MB/s", "duration": 31.028465, "action": "linode_clone", "username": "psnoch", + "entity": {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", + "url": "/v4/linode/instances/101246022"}, "status": "started", "secondary_entity": + {"id": 101246026, "type": "linode", "label": "linode101246026", "url": "/v4/linode/instances/101246026"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "577" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_clone","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode","id":{"+gte":37123330}}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123330, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 35, "time_remaining": "0:1:27", "rate": "283.00 + MB/s", "duration": 46.017819, "action": "linode_clone", "username": "psnoch", + "entity": {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", + "url": "/v4/linode/instances/101246022"}, "status": "started", "secondary_entity": + {"id": 101246026, "type": "linode", "label": "linode101246026", "url": "/v4/linode/instances/101246026"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "577" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_clone","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode","id":{"+gte":37123330}}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123330, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 58, "time_remaining": "0:0:11", "rate": "560.00 + MB/s", "duration": 61.001814, "action": "linode_clone", "username": "psnoch", + "entity": {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", + "url": "/v4/linode/instances/101246022"}, "status": "started", "secondary_entity": + {"id": 101246026, "type": "linode", "label": "linode101246026", "url": "/v4/linode/instances/101246026"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "577" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_clone","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode","id":{"+gte":37123330}}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123330, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 67, "time_remaining": null, "rate": null, + "duration": 76.001585, "action": "linode_clone", "username": "psnoch", "entity": + {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", "url": + "/v4/linode/instances/101246022"}, "status": "started", "secondary_entity": + {"id": 101246026, "type": "linode", "label": "linode101246026", "url": "/v4/linode/instances/101246026"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "564" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_clone","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode","id":{"+gte":37123330}}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123330, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 67, "time_remaining": null, "rate": null, + "duration": 91.044243, "action": "linode_clone", "username": "psnoch", "entity": + {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", "url": + "/v4/linode/instances/101246022"}, "status": "started", "secondary_entity": + {"id": 101246026, "type": "linode", "label": "linode101246026", "url": "/v4/linode/instances/101246026"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "564" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","action":"linode_clone","created":{"+gte":"2018-01-02T03:04:05"},"entity.id":101246022,"entity.type":"linode","id":{"+gte":37123330}}' + url: https://api.linode.com/v4beta/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 37123330, "created": "2018-01-02T03:04:05", "seen": false, + "read": false, "percent_complete": 100, "time_remaining": null, "rate": null, + "duration": 93.0, "action": "linode_clone", "username": "psnoch", "entity": + {"label": "go-test-ins-s56i25fzcj55", "id": 101246022, "type": "linode", "url": + "/v4/linode/instances/101246022"}, "status": "finished", "secondary_entity": + {"id": 101246026, "type": "linode", "label": "linode101246026", "url": "/v4/linode/instances/101246026"}, + "message": "", "details": {}}], "page": 1, "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "561" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - events:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/v4beta/linode/instances/101246022 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/test/integration/fixtures/TestInstance_TryToUpdateLinodeAlertsLegacyAndAclpAtTheSameTime.yaml b/test/integration/fixtures/TestInstance_TryToUpdateLinodeAlertsLegacyAndAclpAtTheSameTime.yaml new file mode 100644 index 000000000..fdc19cc1b --- /dev/null +++ b/test/integration/fixtures/TestInstance_TryToUpdateLinodeAlertsLegacyAndAclpAtTheSameTime.yaml @@ -0,0 +1,245 @@ +--- +version: 1 +interactions: +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/regions?page=1 + method: GET + response: + body: '{"data": [{"id": "pl-labkrk-2", "label": "Krakow, PL", "country": "pl", + "capabilities": ["Linodes", "Block Storage Encryption", "Disk Encryption", "Backups", + "NodeBalancers", "Block Storage", "Object Storage", "GPU Linodes", "Kubernetes", + "Cloud Firewall", "Vlans", "VPCs", "VPC Dual Stack", "VPC IPv6 Stack", "Block + Storage Migrations", "Managed Databases", "Metadata", "Premium Plans", "Placement + Group", "StackScripts", "NETINT Quadra T1U", "Maintenance Policy", "Linode Interfaces", + "ACLP Logs Datacenter LKE-E"], "monitors": {"alerts": ["Linodes", "Managed Databases", + "NodeBalancers", "logs"], "metrics": ["Linodes", "Managed Databases", "NodeBalancers", + "logs"]}, "status": "ok", "resolvers": {"ipv4": "172.24.224.240,172.24.224.229,172.24.224.236,172.24.224.238,172.24.224.235,172.24.224.241,172.24.224.230,172.24.224.239,172.24.224.233,172.24.224.234", + "ipv6": "1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678,1234::5678"}, + "placement_group_limits": {"maximum_pgs_per_customer": null, "maximum_linodes_per_pg": + 5, "maximum_linodes_per_flexible_pg": 5}, "site_type": "core"}], "page": 1, + "pages": 1, "results": 1}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=900 + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - '*' + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"region":"pl-labkrk-2","type":"g6-nanode-1","label":"go-test-ins-a5o9t58qbw27","root_pass":"A0s\u0026''8\u0026U3+BQ2).,Ogb7o4Ot3\u003cdL4\u003cc77u]n$BGkKUHR63b1`|1rNjpu@J8{P=x6","image":"linode/debian12","booted":false}' + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/linode/instances + method: POST + response: + body: '{"id": 101245999, "label": "go-test-ins-a5o9t58qbw27", "group": "", "status": + "provisioning", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", + "type": "g6-nanode-1", "ipv4": ["172.24.244.208"], "ipv6": "1234::5678/128", + "image": "linode/debian12", "region": "pl-labkrk-2", "site_type": "core", "specs": + {"disk": 25600, "memory": 1024, "vcpus": 1, "gpus": 0, "transfer": 1000, "accelerated_devices": + 0}, "alerts": {"cpu": 90, "network_in": 10, "network_out": 10, "transfer_quota": + 80, "io": 10000, "system_alerts": [], "user_alerts": []}, "backups": {"enabled": + false, "available": false, "schedule": {"day": null, "window": null}, "last_successful": + null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": [], "host_uuid": + "e7dbe65d12caf5c1a1de6dc8a495aeb8cc383445", "has_user_data": false, "placement_group": + null, "disk_encryption": "enabled", "lke_cluster_id": null, "capabilities": + ["Block Storage Encryption", "SMTP Enabled", "Maintenance Policy"], "interface_generation": + "legacy_config", "maintenance_policy": "linode/migrate", "locks": []}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "8" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"go-test-ins-a5o9t58qbw27","alerts":{"cpu":50,"io":6000,"network_in":20,"network_out":20,"transfer_quota":50,"system_alerts":[123456],"user_alerts":[1,2]},"watchdog_enabled":true,"tags":[],"group":"","maintenance_policy":"linode/migrate"}' + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/linode/instances/101245999 + method: PUT + response: + body: '{"errors": [{"reason": "Cannot set both legacy and ACLP alerts simultaneously.", + "field": "alerts"}]}' + headers: + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Akamai-Internal-Account: + - '*' + Connection: + - keep-alive + Content-Length: + - "101" + Content-Type: + - application/json + Server: + - nginx + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Frame-Options: + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + status: 400 BAD REQUEST + code: 400 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego/dev https://github.com/linode/linodego + url: https://api.linode.com/v4beta/linode/instances/101245999 + method: DELETE + response: + body: '{}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Akamai-Internal-Account: + - '*' + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "2" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - linodes:read_write + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "400" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" diff --git a/test/integration/instances_test.go b/test/integration/instances_test.go index e925a71fd..017ecbbcf 100644 --- a/test/integration/instances_test.go +++ b/test/integration/instances_test.go @@ -9,6 +9,7 @@ import ( "testing" "github.com/linode/linodego" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -22,75 +23,59 @@ func TestInstances_List_smoke(t *testing.T) { defer teardown() - if err != nil { - t.Error(err) - } + require.NoError(t, err) listOpts := linodego.NewListOptions(1, "{\"id\": "+strconv.Itoa(instance.ID)+"}") linodes, err := client.ListInstances(context.Background(), listOpts) - if err != nil { - t.Errorf("Error listing instances, expected struct, got error %v", err) - } - if len(linodes) != 1 { - t.Errorf("Expected a list of instances, but got %v", linodes) - } - - if linodes[0].ID != instance.ID { - t.Errorf("Expected list of instances to include test instance, but got %v", linodes) - } - - if linodes[0].HostUUID == "" { - t.Errorf("failed to get instance HostUUID") - } - - if linodes[0].HasUserData { - t.Errorf("expected instance.HasUserData to be false, got true") - } - - if linodes[0].Specs.GPUs < 0 { - t.Errorf("failed to retrieve number of GPUs") - } + require.NoErrorf(t, err, "Error listing instances, expected struct, got error %v", err) + require.Equalf(t, 1, len(linodes), "Expected a list of instances, but got %v", linodes) + require.Equalf(t, instance.ID, linodes[0].ID, + "Expected list of instances to include test instance, but got %v", linodes) + require.NotEmptyf(t, linodes[0].HostUUID, "failed to get instance HostUUID") + require.Falsef(t, linodes[0].HasUserData, "expected instance.HasUserData to be false, got true") + require.GreaterOrEqualf(t, linodes[0].Specs.GPUs, 0, "failed to retrieve number of GPUs") + + assert.GreaterOrEqual(t, linodes[0].Alerts.CPU, 0) + assert.GreaterOrEqual(t, linodes[0].Alerts.IO, 0) + assert.GreaterOrEqual(t, linodes[0].Alerts.NetworkIn, 0) + assert.GreaterOrEqual(t, linodes[0].Alerts.NetworkOut, 0) + assert.GreaterOrEqual(t, linodes[0].Alerts.TransferQuota, 0) + assert.NotNil(t, linodes[0].Alerts.SystemAlerts) + assert.NotNil(t, linodes[0].Alerts.UserAlerts) } func TestInstance_Get_smoke(t *testing.T) { client, instance, _, teardown, err := setupInstanceWithoutDisks(t, "fixtures/TestInstance_Get", true) defer teardown() - if err != nil { - t.Error(err) - } + require.NoError(t, err) settings, err := client.GetAccountSettings(context.Background()) - if err != nil { - t.Fatalf("Failed to get account settings: %s", err) - } + require.NoErrorf(t, err, "Failed to get account settings: %s", err) defaultPolicy := settings.MaintenancePolicy _, err = client.UpdateInstance(context.Background(), instance.ID, linodego.InstanceUpdateOptions{ MaintenancePolicy: &defaultPolicy, }) - if err != nil { - t.Fatalf("Error setting maintenance policy: %s", err) - } + require.NoErrorf(t, err, "Error setting maintenance policy: %s", err) instanceGot, err := client.GetInstance(context.Background(), instance.ID) - if err != nil { - t.Errorf("Error getting instance: %s", err) - } - if instanceGot.ID != instance.ID { - t.Errorf("Expected instance ID %d to match %d", instanceGot.ID, instance.ID) - } - if instanceGot.MaintenancePolicy != defaultPolicy { - t.Errorf("Expected maintenance policy %q, got %q", defaultPolicy, instanceGot.MaintenancePolicy) - } - if instanceGot.Specs.Disk <= 0 { - t.Errorf("Error parsing instance spec for disk size: %v", instanceGot.Specs) - } - if instanceGot.HostUUID == "" { - t.Errorf("failed to get instance HostUUID") - } + require.NoError(t, err, "Error getting instance: %s", err) + require.Equal(t, instance.ID, instanceGot.ID) + require.Equal(t, defaultPolicy, instanceGot.MaintenancePolicy) + require.Greaterf(t, instanceGot.Specs.Disk, 0, + "Error parsing instance spec for disk size: %v", instanceGot.Specs) + require.NotEmpty(t, instanceGot.HostUUID, "failed to get instance HostUUID") assertDateSet(t, instanceGot.Created) assertDateSet(t, instanceGot.Updated) + + assert.Greater(t, instanceGot.Alerts.CPU, 0) + assert.Greater(t, instanceGot.Alerts.IO, 0) + assert.GreaterOrEqual(t, instanceGot.Alerts.NetworkIn, 0) + assert.GreaterOrEqual(t, instanceGot.Alerts.NetworkOut, 0) + assert.GreaterOrEqual(t, instanceGot.Alerts.TransferQuota, 0) + assert.NotNil(t, instanceGot.Alerts.SystemAlerts) + assert.NotNil(t, instanceGot.Alerts.UserAlerts) } func TestInstance_GetTransfer(t *testing.T) { @@ -697,14 +682,10 @@ func TestInstance_Rebuild(t *testing.T) { ) defer teardown() - if err != nil { - t.Error(err) - } + require.NoError(t, err) _, err = client.WaitForEventFinished(context.Background(), instance.ID, linodego.EntityLinode, linodego.ActionLinodeCreate, *instance.Created, 180) - if err != nil { - t.Errorf("Error waiting for instance created: %s", err) - } + require.NoErrorf(t, err, "Error waiting for instance created: %s", err) rebuildOpts := linodego.InstanceRebuildOptions{ Image: "linode/alpine3.19", @@ -715,13 +696,11 @@ func TestInstance_Rebuild(t *testing.T) { Type: "g6-standard-2", } instance, err = client.RebuildInstance(context.Background(), instance.ID, rebuildOpts) - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) - if !instance.HasUserData { - t.Fatal("expected instance.HasUserData to be true, got false") - } + require.True(t, instance.HasUserData, "expected instance.HasUserData to be true, got false") + assert.GreaterOrEqual(t, instance.Alerts.CPU, 0) + assert.GreaterOrEqual(t, instance.Alerts.IO, 0) } func TestInstance_RebuildWithEncryption(t *testing.T) { @@ -956,6 +935,131 @@ func TestInstance_withPG(t *testing.T) { require.Equal(t, inst.PlacementGroup.PlacementGroupPolicy, pg.PlacementGroupPolicy) } +func TestLinodeAlertsWorkflow(t *testing.T) { + client, teardown := createTestClient(t, + "fixtures/TestInstance_AlertsWorkflow") + defer teardown() + + region := getRegions(t, client)[0].ID + instance, err := createInstance( + t, + client, + false, + func(l *linodego.Client, options *linodego.InstanceCreateOptions) { + options.Region = region + }, + ) + require.NoError(t, err) + defer func() { + err := client.DeleteInstance(context.Background(), instance.ID) + require.NoError(t, err) + }() + assert.Equal(t, 90, instance.Alerts.CPU) + assert.Equal(t, 10000, instance.Alerts.IO) + assert.Equal(t, 10, instance.Alerts.NetworkIn) + assert.Equal(t, 10, instance.Alerts.NetworkOut) + assert.Equal(t, 80, instance.Alerts.TransferQuota) + assert.Empty(t, instance.Alerts.SystemAlerts) + assert.Empty(t, instance.Alerts.UserAlerts) + _, err = client.WaitForEventFinished( + context.Background(), + instance.ID, + linodego.EntityLinode, + linodego.ActionLinodeCreate, + *instance.Created, + 180, + ) + require.NoErrorf(t, err, "Error waiting for instance created: %s", err) + updateOpts := instance.GetUpdateOptions() + alertsUpdateOpts := linodego.InstanceAlert{ + CPU: 50, + IO: 6000, + NetworkIn: 20, + NetworkOut: 20, + TransferQuota: 50, + } + updateOpts.Alerts = &alertsUpdateOpts + updateOpts.Backups = nil + updateResponse, errUpdate := client.UpdateInstance(context.Background(), instance.ID, updateOpts) + require.NoError(t, errUpdate) + assert.Equal(t, 50, updateResponse.Alerts.CPU) + assert.Equal(t, 6000, updateResponse.Alerts.IO) + assert.Equal(t, 20, updateResponse.Alerts.NetworkIn) + assert.Equal(t, 20, updateResponse.Alerts.NetworkOut) + assert.Equal(t, 50, updateResponse.Alerts.TransferQuota) + assert.Empty(t, updateResponse.Alerts.SystemAlerts) + assert.Empty(t, updateResponse.Alerts.UserAlerts) + + cloneOptions := linodego.InstanceCloneOptions{ + Region: region, + Type: "g6-nanode-1", + Alerts: &linodego.InstanceACLPAlertsOptions{ + SystemAlerts: []int{}, + }, + } + clonedInstance, err := client.CloneInstance(context.Background(), instance.ID, cloneOptions) + require.NoError(t, err) + t.Cleanup(func() { + err := client.DeleteInstance(context.Background(), clonedInstance.ID) + require.NoError(t, err) + }) + assert.Equal(t, 90, clonedInstance.Alerts.CPU) + assert.Equal(t, 10000, clonedInstance.Alerts.IO) + assert.Equal(t, 10, clonedInstance.Alerts.NetworkIn) + assert.Equal(t, 10, clonedInstance.Alerts.NetworkOut) + assert.Equal(t, 80, clonedInstance.Alerts.TransferQuota) + assert.Empty(t, clonedInstance.Alerts.SystemAlerts) + assert.Empty(t, clonedInstance.Alerts.UserAlerts) + + _, err = client.WaitForEventFinished( + context.Background(), + instance.ID, + linodego.EntityLinode, + linodego.ActionLinodeClone, + *clonedInstance.Created, + 240, + ) + require.NoError(t, err) +} + +func TestTryToUpdateLinodeAlertsLegacyAndAclpAtTheSameTime(t *testing.T) { + client, teardown := createTestClient(t, + "fixtures/TestInstance_TryToUpdateLinodeAlertsLegacyAndAclpAtTheSameTime") + defer teardown() + + region := getRegions(t, client)[0].ID + instToUpdate, err := createInstance( + t, + client, + false, + func(l *linodego.Client, options *linodego.InstanceCreateOptions) { + options.Region = region + }, + ) + require.NoError(t, err) + defer func() { + err := client.DeleteInstance(context.Background(), instToUpdate.ID) + require.NoError(t, err) + }() + + updateOpts := instToUpdate.GetUpdateOptions() + alertsUpdateData := linodego.InstanceAlert{ + CPU: 50, + IO: 6000, + NetworkIn: 20, + NetworkOut: 20, + TransferQuota: 50, + SystemAlerts: []int{123456}, + UserAlerts: []int{1, 2}, + } + updateOpts.Alerts = &alertsUpdateData + updateOpts.Backups = nil + _, errUpdate := client.UpdateInstance(context.Background(), instToUpdate.ID, updateOpts) + require.Error(t, errUpdate) + assert.Contains(t, errUpdate.Error(), "[400] [alerts] Cannot set both legacy " + + "and ACLP alerts simultaneously") +} + func createInstance(t *testing.T, client *linodego.Client, enableCloudFirewall bool, modifiers ...instanceModifier) (*linodego.Instance, error) { if t != nil { t.Helper() diff --git a/test/integration/integration_suite_test.go b/test/integration/integration_suite_test.go index 3ca0cb8a2..32fa681e3 100644 --- a/test/integration/integration_suite_test.go +++ b/test/integration/integration_suite_test.go @@ -274,6 +274,19 @@ func getRegionsWithCapsAndSiteType(t *testing.T, client *linodego.Client, capabi return result } +func getRegions(t *testing.T, client *linodego.Client) []linodego.Region { + regions, err := client.ListRegions(context.Background(), nil) + require.NoError(t, err) + okRegions := make([]linodego.Region, 0, len(regions)) + for _, region := range regions { + if region.Status == "ok" { + okRegions = append(okRegions, region) + } + } + require.GreaterOrEqual(t, len(okRegions), 1, "expected at least one region with Status == \"ok\"") + return okRegions +} + func regionHasCaps(r linodego.Region, capabilities []string) bool { capsMap := make(map[string]bool)