From d6a8a082d43c3bdf719d0725b571f4ac525b533f Mon Sep 17 00:00:00 2001 From: phillc <15082+phillc@users.noreply.github.com> Date: Thu, 2 Apr 2020 09:34:59 -0400 Subject: [PATCH] InstanceRebuildOptions no longer requires all fields to be specified --- instances.go | 14 +- .../fixtures/TestRebuildInstance.yaml | 373 ++++++++++++++++++ test/integration/instances_test.go | 25 ++ 3 files changed, 405 insertions(+), 7 deletions(-) create mode 100644 test/integration/fixtures/TestRebuildInstance.yaml diff --git a/instances.go b/instances.go index 77a9def9f..abb807fb5 100644 --- a/instances.go +++ b/instances.go @@ -398,13 +398,13 @@ func (c *Client) RebootInstance(ctx context.Context, id int, configID int) error // InstanceRebuildOptions is a struct representing the options to send to the rebuild linode endpoint type InstanceRebuildOptions struct { - Image string `json:"image"` - RootPass string `json:"root_pass"` - AuthorizedKeys []string `json:"authorized_keys"` - AuthorizedUsers []string `json:"authorized_users"` - StackscriptID int `json:"stackscript_id"` - StackscriptData map[string]string `json:"stackscript_data"` - Booted bool `json:"booted"` + Image string `json:"image,omitempty"` + RootPass string `json:"root_pass,omitempty"` + AuthorizedKeys []string `json:"authorized_keys,omitempty"` + AuthorizedUsers []string `json:"authorized_users,omitempty"` + StackScriptID int `json:"stackscript_id,omitempty"` + StackScriptData map[string]string `json:"stackscript_data,omitempty"` + Booted *bool `json:"booted,omitempty"` } // RebuildInstance Deletes all Disks and Configs on this Linode, diff --git a/test/integration/fixtures/TestRebuildInstance.yaml b/test/integration/fixtures/TestRebuildInstance.yaml new file mode 100644 index 000000000..e247703e5 --- /dev/null +++ b/test/integration/fixtures/TestRebuildInstance.yaml @@ -0,0 +1,373 @@ +--- +version: 1 +interactions: +- request: + body: '{"region":"us-west","type":"g6-nanode-1","label":"linodego-test-instance-wo-disk","booted":false}' + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego 0.12.0 https://github.com/linode/linodego + url: https://api.linode.com/v4beta/linode/instances + method: POST + response: + body: '{"id": 19977966, "label": "linodego-test-instance-wo-disk", "group": "", + "status": "provisioning", "created": "2020-04-02T13:34:23", "updated": "2020-04-02T13:34:23", + "type": "g6-nanode-1", "ipv4": ["45.33.51.250"], "ipv6": "2600:3c01::f03c:92ff:fe60:213f/64", + "image": null, "region": "us-west", "specs": {"disk": 25600, "memory": 1024, + "vcpus": 1, "gpus": 0, "transfer": 1000}, "alerts": {"cpu": 90, "network_in": + 10, "network_out": 10, "transfer_quota": 80, "io": 10000}, "backups": {"enabled": + false, "schedule": {"day": null, "window": null}, "last_successful": null}, + "hypervisor": "kvm", "watchdog_enabled": true, "tags": []}' + 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 + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "632" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Thu, 02 Apr 2020 13:34:23 GMT + Retry-After: + - "80" + 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: + - "1600" + X-Ratelimit-Remaining: + - "1584" + X-Ratelimit-Reset: + - "1585834544" + X-Spec-Version: + - 4.60.0 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"label":"linodego-test-config","devices":{}}' + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego 0.12.0 https://github.com/linode/linodego + url: https://api.linode.com/v4beta/linode/instances/19977966/configs + method: POST + response: + body: '{"id": 21359003, "label": "linodego-test-config", "helpers": {"updatedb_disabled": + true, "distro": true, "modules_dep": true, "network": true, "devtmpfs_automount": + true}, "kernel": "linode/latest-64bit", "comments": "", "memory_limit": 0, "created": + "2020-04-02T13:34:24", "updated": "2020-04-02T13:34:24", "root_device": "/dev/sda", + "devices": {"sda": null, "sdb": null, "sdc": null, "sdd": null, "sde": null, + "sdf": null, "sdg": null, "sdh": null}, "initrd": null, "run_level": "default", + "virt_mode": "paravirt"}' + 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 + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "516" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Thu, 02 Apr 2020 13:34:24 GMT + Retry-After: + - "80" + 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: + - "1600" + X-Ratelimit-Remaining: + - "1583" + X-Ratelimit-Reset: + - "1585834545" + X-Spec-Version: + - 4.60.0 + 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 0.12.0 https://github.com/linode/linodego + X-Filter: + - '{"+order":"desc","+order_by":"created","entity.id":19977966,"entity.type":"linode","seen":false}' + url: https://api.linode.com/v4beta/account/events?page=1 + method: GET + response: + body: '{"data": [{"id": 79314392, "created": "2020-04-02T13:34:24", "seen": false, + "read": false, "percent_complete": null, "time_remaining": null, "rate": null, + "duration": null, "action": "linode_config_create", "username": "pccampbell", + "entity": {"label": "linodego-test-instance-wo-disk", "id": 19977966, "type": + "linode", "url": "/v4/linode/instances/19977966"}, "status": "notification", + "secondary_entity": {"id": 21359003, "type": "linode_config", "label": "linodego-test-config", + "url": "/v4/linode/instances/19977966/configs/21359003"}}, {"id": 79314390, + "created": "2020-04-02T13:34:23", "seen": false, "read": false, "percent_complete": + 100, "time_remaining": 0, "rate": null, "duration": 5.0, "action": "linode_create", + "username": "pccampbell", "entity": {"label": "linodego-test-instance-wo-disk", + "id": 19977966, "type": "linode", "url": "/v4/linode/instances/19977966"}, "status": + "finished", "secondary_entity": null}], "page": 1, "pages": 1, "results": 2}' + 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 + 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: + - "968" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Thu, 02 Apr 2020 13:34:39 GMT + Retry-After: + - "64" + 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: + - "1600" + X-Ratelimit-Remaining: + - "1582" + X-Ratelimit-Reset: + - "1585834544" + X-Spec-Version: + - 4.60.0 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: '{"image":"linode/alpine3.11","root_pass":"R34lBAdP455"}' + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego 0.12.0 https://github.com/linode/linodego + url: https://api.linode.com/v4beta/linode/instances/19977966/rebuild + method: POST + response: + body: '{"id": 19977966, "label": "linodego-test-instance-wo-disk", "group": "", + "status": "rebuilding", "created": "2020-04-02T13:34:23", "updated": "2020-04-02T13:34:23", + "type": "g6-nanode-1", "ipv4": ["45.33.51.250"], "ipv6": "2600:3c01::f03c:92ff:fe60:213f/64", + "image": "linode/alpine3.11", "region": "us-west", "specs": {"disk": 25600, + "memory": 1024, "vcpus": 1, "gpus": 0, "transfer": 1000}, "alerts": {"cpu": + 90, "network_in": 10, "network_out": 10, "transfer_quota": 80, "io": 10000}, + "backups": {"enabled": false, "schedule": {"day": null, "window": null}, "last_successful": + null}, "hypervisor": "kvm", "watchdog_enabled": true, "tags": []}' + 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 + Cache-Control: + - private, max-age=60, s-maxage=60 + Connection: + - keep-alive + Content-Length: + - "645" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Date: + - Thu, 02 Apr 2020 13:34:40 GMT + Retry-After: + - "64" + 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: + - "1600" + X-Ratelimit-Remaining: + - "1581" + X-Ratelimit-Reset: + - "1585834545" + X-Spec-Version: + - 4.60.0 + 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 0.12.0 https://github.com/linode/linodego + url: https://api.linode.com/v4beta/linode/instances/19977966 + 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 + 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 + Date: + - Thu, 02 Apr 2020 13:34:40 GMT + Retry-After: + - "63" + 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: + - "1600" + X-Ratelimit-Remaining: + - "1580" + X-Ratelimit-Reset: + - "1585834544" + X-Spec-Version: + - 4.60.0 + 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 c805539d0..0d91e6261 100644 --- a/test/integration/instances_test.go +++ b/test/integration/instances_test.go @@ -289,6 +289,31 @@ func TestListInstanceVolumes(t *testing.T) { } } +func TestRebuildInstance(t *testing.T) { + client, instance, _, teardown, err := setupInstanceWithoutDisks(t, "fixtures/TestRebuildInstance") + defer teardown() + + if err != nil { + t.Error(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) + } + + rebuildOpts := linodego.InstanceRebuildOptions{ + Image: "linode/alpine3.11", + RootPass: "R34lBAdP455", + } + instance, err = client.RebuildInstance(context.Background(), instance.ID, rebuildOpts) + + if err != nil { + t.Error(err) + } +} + func setupInstance(t *testing.T, fixturesYaml string) (*linodego.Client, *linodego.Instance, func(), error) { if t != nil { t.Helper()