Skip to content
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# kitchen-oci CHANGELOG

# 1.27.0
- feat: extend `post_create_script` to accept a list of script files
- doc: add YARD tags to all methods and classes and add `metadata` to the gemspec

# 1.26.0
- feat: generate rsa key pair automatically per instance

# 1.25.0
- feat: allow `image_name` to function the same for ARM as it does for Linux

Expand Down
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Kitchen::OCI

[![Gem Version](https://badge.fury.io/rb/kitchen-oci.svg)](https://badge.fury.io/rb/kitchen-oci)

A Test Kitchen Driver for Oracle Cloud Infrastructure (OCI)

`kitchen-oci` can create two types of instances:
Expand Down Expand Up @@ -51,7 +53,7 @@ The following driver parameters are common to both instance types, but are not r
- `oci_config`, Hash of additional `OCI::Config` settings. Allows you to test without an oci config file [[more](#use-without-oci-config-file)]
- `ssh_keypath`, SSH public key (default: `~/.ssh/id_rsa.pub`)
- `ssh_keygen`, Automatically generate the rsa key pair for an instance (default: `false`) [[more](#ssh-keygen)]
- `post_create_script`, run a script on an instance after deployment
- `post_create_script`, run a script on an instance after deployment [[more](#post-create-script)]
- `post_create_reboot`, reboot the instance after instance creation (default: `false`)
- `proxy_url`, Connect via the specified proxy URL [[more](#proxy-support)]
- `defined_tags`, Hash containing tag name(s) and values(s). Each key must be predefined and scoped into a namespace.
Expand Down Expand Up @@ -152,7 +154,6 @@ Optional settings for WinRM support in Windows [[more](#windows-support)]:
custom_metadata:
key1: value1
key2: value2
post_create_script: >-
```

## DBaaS Instance Type
Expand Down Expand Up @@ -275,6 +276,32 @@ Alternately, if you simply pass a string to the user_data, it will be base64 enc
gid: 1000
```

## Post Create Script

The `post_create_script` property is another means of executing a command or series of commands on the instance. The scripts or commands specified in `post_create_script` are executed after `cloud-init`, but before `post_create` lifecycle hooks.

This property accepts both inline scripts and list of files. Examples:

Passing a command as a string:

```yml
driver:
name: oci
post_create_script: echo "here i am running a post_create_script"
```

Passing a list of script files:

```yml
driver:
name: oci
post_create_script:
- ./path/to/my/fixture/script.sh
- ./path/to/a/second/fixture/script.sh
```

These scripts are executed by the user specified as the transport username (most likely `opc` or `ubuntu`) so any privilege elevation would need to be gained via `sudo` or the `elevated: true` property of the `WinRM` transport.

## SSH Keygen

The driver can generate an ssh key pair for an instance during creation. In order to turn this feature on, add the `ssh_keygen` property to the `driver` and set the value to `true`. This can be set in the `driver` section on a
Expand Down Expand Up @@ -481,9 +508,8 @@ WIN_IMAGE_ID

These environment variables should align with your tenancy and the region in which you intend to test.

There is a kitchen.yml file in the `test/integration/fixtures` directory in this project that can be used to test the gem. From this
directory, execute `bundle exec kitchen list` to see a list of instances. All normal kitchen commands work within the `bundle exec`
context from here.
There is a [kitchen.yml](test/integration/fixtures/kitchen.yml) in this project that can be used to test the gem. From the same directory as the [kitchen.yml](test/integration/fixtures/kitchen.yml),
execute `bundle exec kitchen list` to see a list of instances. All normal kitchen commands work within the `bundle exec` context from here.

## Maintainer

Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/driver/oci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def create(state)
inst = instance_class(config, state, oci, api, __method__)
launch(state, inst)
create_and_attach_volumes(config, state, oci, api)
process_post_script(state)
execute_post_create_script(state)
reboot(state, inst)
end

Expand Down
24 changes: 23 additions & 1 deletion lib/kitchen/driver/oci/mixin/actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,36 @@ def launch(state, inst)
# Executes the post script on the instance.
#
# @param state [Hash] (see Kitchen::StateFile)
def process_post_script(state)
def execute_post_create_script(state)
return if config[:post_create_script].nil?

if config[:post_create_script].is_a?(String)
execute_post_create_string(state)
elsif config[:post_create_script].is_a?(Array)
execute_post_create_file(state)
end
end

# Executes the post create script from a String.
#
# @param state [Hash] (see Kitchen::StateFile)
def execute_post_create_string(state)
info("Running post create script")
script = config[:post_create_script]
instance.transport.connection(state).execute(script)
end

# Reads the specified file and executes as a post create script.
#
# @param state [Hash] (see Kitchen::StateFile)
def execute_post_create_file(state)
config[:post_create_script].each do |script|
info("Running post create script #{File.basename(script)}")
script = File.read script
instance.transport.connection(state).execute(script)
end
end

# Reboots an instance.
#
# @param state [Hash] (see Kitchen::StateFile)
Expand Down
4 changes: 3 additions & 1 deletion lib/kitchen/driver/oci_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
module Kitchen
module Driver
# Version string for Oracle OCI Kitchen driver
OCI_VERSION = "1.26.0"
#
# @author Stephen Pearson (<stephen.pearson@oracle.com>)
OCI_VERSION = "1.27.0"
end
end