vagrant-timezone 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rspec +5 -0
- data/.rubocop.yml +42 -0
- data/.travis.yml +14 -9
- data/CHANGELOG.md +12 -0
- data/Gemfile +14 -3
- data/Guardfile +23 -0
- data/LICENSE.txt +1 -1
- data/README.md +2 -2
- data/Rakefile +22 -6
- data/lib/vagrant-timezone/action/set_timezone.rb +4 -3
- data/lib/vagrant-timezone/cap/debian.rb +5 -3
- data/lib/vagrant-timezone/cap/gentoo.rb +9 -9
- data/lib/vagrant-timezone/cap/linux.rb +35 -0
- data/lib/vagrant-timezone/cap/redhat.rb +6 -5
- data/lib/vagrant-timezone/config.rb +1 -1
- data/lib/vagrant-timezone/plugin.rb +16 -34
- data/lib/vagrant-timezone/version.rb +1 -1
- data/locales/en.yml +1 -1
- data/tasks/acceptance.rake +42 -0
- data/test/acceptance/config/boxes.yaml +8 -0
- data/test/acceptance/config/vagrant-spec.config.rb +13 -0
- data/test/acceptance/skeletons/timezone/Vagrantfile +10 -0
- data/test/acceptance/support/box_helper.rb +112 -0
- data/test/acceptance/support/spec_helper.rb +16 -0
- data/test/acceptance/vagrant-timezone/timezone_spec.rb +82 -0
- data/test/spec_helper.rb +3 -0
- data/{spec → test}/unit/vagrant-timezone/cap/windows_spec.rb +2 -1
- data/{spec → test}/unit/vagrant-timezone/config_spec.rb +3 -2
- data/vagrant-timezone.gemspec +2 -3
- metadata +26 -12
- data/lib/vagrant-timezone/cap/arch.rb +0 -13
- data/lib/vagrant-timezone/cap/coreos.rb +0 -13
- data/spec/spec_helper.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4f3f7a021665f40589dcca99456a0d051b841a066b96e0acb2519724d7f6e418
|
4
|
+
data.tar.gz: d99773373bc1d2d3f9c520ed211e82738a5e894f835eb5bfd64b20b768ac6299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df75274bfc5c09b51d5972d8c0c70330d99118af12118f8eda3a30a77d5bfc623ef599637d6955d883aa746875b46137b1a231a8c70a36dafb013ab3d96e98a2
|
7
|
+
data.tar.gz: bf6fcae47144ad121424154ae803223e0c062571f9d93ac358853724c859c27c6cadd1ba0f95262178b9250168e7a457a1bec46721af3bd55ea3011eb8306f15
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayStyleGuide: true
|
3
|
+
ExtraDetails: true
|
4
|
+
TargetRubyVersion: 2.2
|
5
|
+
|
6
|
+
Layout/AlignHash:
|
7
|
+
EnforcedHashRocketStyle: table
|
8
|
+
EnforcedColonStyle: table
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Exclude:
|
12
|
+
- '*.gemspec'
|
13
|
+
- '**/*.rake'
|
14
|
+
- '**/*_spec.rb'
|
15
|
+
|
16
|
+
Metrics/ClassLength:
|
17
|
+
Severity: warning
|
18
|
+
|
19
|
+
Metrics/LineLength:
|
20
|
+
Max: 100
|
21
|
+
Severity: warning
|
22
|
+
|
23
|
+
Metrics/MethodLength:
|
24
|
+
Max: 13
|
25
|
+
Severity: warning
|
26
|
+
|
27
|
+
Naming/FileName:
|
28
|
+
Exclude:
|
29
|
+
- 'lib/vagrant-timezone.rb'
|
30
|
+
- '**/vagrant-spec.config.rb'
|
31
|
+
|
32
|
+
Style/GuardClause:
|
33
|
+
MinBodyLength: 3
|
34
|
+
|
35
|
+
Style/NegatedIf:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
Style/TrailingCommaInArrayLiteral:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
Style/TrailingCommaInHashLiteral:
|
42
|
+
Enabled: false
|
data/.travis.yml
CHANGED
@@ -2,19 +2,24 @@ language: ruby
|
|
2
2
|
cache: bundler
|
3
3
|
sudo: false
|
4
4
|
|
5
|
-
before_install:
|
6
|
-
- rvm @global do gem uninstall bundler --all --executables
|
7
|
-
- gem uninstall bundler --all --executables
|
8
|
-
- gem install bundler --version '~> 1.5.2'
|
9
|
-
- bundle --version
|
10
5
|
bundler_args: --without=development
|
11
6
|
|
12
|
-
|
13
|
-
|
7
|
+
script:
|
8
|
+
- bundle exec rake test:unit
|
9
|
+
- bundle exec rake style
|
10
|
+
|
11
|
+
env:
|
12
|
+
global:
|
13
|
+
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
|
14
|
+
|
15
|
+
rvm: 2.4.4
|
14
16
|
matrix:
|
15
17
|
include:
|
16
|
-
- env: VAGRANT_VERSION=
|
17
|
-
|
18
|
+
- env: VAGRANT_VERSION=v2.2.3
|
19
|
+
- env: VAGRANT_VERSION=v2.0.4
|
20
|
+
- env:
|
21
|
+
- VAGRANT_VERSION=v1.9.8
|
22
|
+
rvm: 2.2.5
|
18
23
|
- env: VAGRANT_VERSION=master
|
19
24
|
allow_failures:
|
20
25
|
- env: VAGRANT_VERSION=master
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# 1.3.0 / 2019-01-10
|
2
|
+
|
3
|
+
- Use `timedatectl` on all Linux distributions if found ([GH-10][], [GH-7][], [GH-5][])
|
4
|
+
* `systemd` is now used on many Linux distros (e.g. Debian based ones)
|
5
|
+
|
6
|
+
- Improve testing by adding acceptance and style tests ([GH-11][])
|
7
|
+
|
8
|
+
[GH-5]: https://github.com/tmatilai/vagrant-timezone/issues/5 "Issue 5"
|
9
|
+
[GH-7]: https://github.com/tmatilai/vagrant-timezone/issues/7 "Issue 7"
|
10
|
+
[GH-10]: https://github.com/tmatilai/vagrant-timezone/issues/10 "Issue 10"
|
11
|
+
[GH-11]: https://github.com/tmatilai/vagrant-timezone/issues/11 "Issue 11"
|
12
|
+
|
1
13
|
# 1.2.0 / 2017-02-25
|
2
14
|
|
3
15
|
Features:
|
data/Gemfile
CHANGED
@@ -1,12 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
gem 'vagrant',
|
4
|
-
|
5
|
-
|
6
|
+
git: 'https://github.com/hashicorp/vagrant.git',
|
7
|
+
tag: ENV.fetch('VAGRANT_VERSION', 'v2.2.3')
|
6
8
|
|
7
9
|
gem 'rake'
|
8
10
|
gem 'rspec', '~> 3.1'
|
11
|
+
gem 'rubocop', '~> 0.62'
|
12
|
+
|
13
|
+
gem 'vagrant-spec',
|
14
|
+
git: 'https://github.com/hashicorp/vagrant-spec.git'
|
15
|
+
|
16
|
+
group :development do
|
17
|
+
gem 'guard-rspec', '~> 4.7'
|
18
|
+
gem 'guard-rubocop', '~> 1.3'
|
19
|
+
end
|
9
20
|
|
10
21
|
group :plugins do
|
11
|
-
|
22
|
+
gemspec
|
12
23
|
end
|
data/Guardfile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
spec_dir = 'test/unit'
|
4
|
+
|
5
|
+
group :ruby, halt_on_fail: true do
|
6
|
+
guard :rspec, cmd: 'bundle exec rspec --format progress', spec_paths: [spec_dir] do
|
7
|
+
# RSpec files
|
8
|
+
watch('test/spec_helper.rb') { spec_dir }
|
9
|
+
watch(%r{^#{spec_dir}/.+_spec\.rb$})
|
10
|
+
|
11
|
+
# Ruby files
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "#{spec_dir}/#{m[1]}_spec.rb" }
|
13
|
+
end
|
14
|
+
|
15
|
+
guard :rubocop do
|
16
|
+
watch(/\.rb$/)
|
17
|
+
watch(/\.gemspec$/)
|
18
|
+
watch('Gemfile')
|
19
|
+
watch('Rakefile')
|
20
|
+
watch(%r{/Vagrantfile$})
|
21
|
+
watch('.rubocop.yml') { '.' }
|
22
|
+
end
|
23
|
+
end
|
data/LICENSE.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2014-
|
3
|
+
Copyright (c) 2014-2019 Teemu Matilainen <teemu.matilainen@iki.fi>
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -45,14 +45,14 @@ The plugin is supposed to be compatible with all Vagrant providers and other plu
|
|
45
45
|
|
46
46
|
At the moment the supported platforms include:
|
47
47
|
|
48
|
-
- Linux:
|
48
|
+
- All Linux guests. Confirmed at least:
|
49
49
|
* Arch
|
50
50
|
* CoreOS
|
51
51
|
* Debian (and derivatives)
|
52
52
|
* Gentoo
|
53
53
|
* RedHat (and derivatives)
|
54
54
|
|
55
|
-
- BSD:
|
55
|
+
- All BSD guests:
|
56
56
|
* FreeBSD
|
57
57
|
* NetBSD
|
58
58
|
* OpenBSD
|
data/Rakefile
CHANGED
@@ -1,14 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler/gem_tasks'
|
2
4
|
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
3
6
|
|
4
|
-
task default: 'test:unit'
|
7
|
+
task default: ['test:unit', 'style']
|
5
8
|
|
6
|
-
|
7
|
-
|
9
|
+
desc 'Run all tests'
|
10
|
+
task test: ['test:unit', 'test:acceptance']
|
8
11
|
|
9
12
|
namespace :test do
|
10
|
-
|
11
|
-
|
13
|
+
desc 'Run unit tests'
|
14
|
+
RSpec::Core::RakeTask.new(:unit) do |task|
|
15
|
+
task.pattern = 'test/unit/**/*_spec.rb'
|
12
16
|
end
|
17
|
+
|
18
|
+
load 'tasks/acceptance.rake'
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Run all style checks'
|
22
|
+
task style: ['style:ruby']
|
23
|
+
|
24
|
+
namespace :style do
|
25
|
+
desc 'Run style checks for Ruby'
|
26
|
+
RuboCop::RakeTask.new(:ruby)
|
13
27
|
end
|
14
|
-
|
28
|
+
|
29
|
+
# Remove 'install' task as the gem is installed to Vagrant, not to system
|
30
|
+
Rake::Task[:install].clear
|
@@ -5,19 +5,20 @@ module VagrantPlugins
|
|
5
5
|
module Action
|
6
6
|
# Vagrant middleware action that sets the specified time zone
|
7
7
|
class SetTimeZone
|
8
|
-
def initialize(app,
|
8
|
+
def initialize(app, _env)
|
9
9
|
@app = app
|
10
10
|
end
|
11
11
|
|
12
|
-
def call(env)
|
12
|
+
def call(env) # rubocop:disable Metrics/AbcSize
|
13
13
|
@app.call(env)
|
14
14
|
|
15
15
|
machine = env[:machine]
|
16
16
|
timezone = machine.config.timezone.value
|
17
|
+
|
17
18
|
if timezone.nil?
|
18
19
|
logger.info I18n.t('vagrant_timezone.not_enabled')
|
19
20
|
elsif machine.guest.capability?(:change_timezone)
|
20
|
-
env[:ui].info I18n.t('vagrant_timezone.configuring')
|
21
|
+
env[:ui].info I18n.t('vagrant_timezone.configuring', zone: timezone)
|
21
22
|
machine.guest.capability(:change_timezone, timezone)
|
22
23
|
else
|
23
24
|
logger.info I18n.t('vagrant_timezone.not_supported')
|
@@ -1,10 +1,12 @@
|
|
1
|
+
require_relative 'linux'
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module TimeZone
|
3
5
|
module Cap
|
4
6
|
# Debian capabilities for changing time zone
|
5
|
-
class Debian
|
6
|
-
# Set the time zone
|
7
|
-
def self.
|
7
|
+
class Debian < Linux
|
8
|
+
# Set the time zone if `timedatectl` is not found
|
9
|
+
def self.change_timezone_generic(machine, timezone)
|
8
10
|
machine.communicate.tap do |comm|
|
9
11
|
comm.sudo("echo '#{timezone}' > /etc/timezone")
|
10
12
|
comm.sudo('dpkg-reconfigure --frontend noninteractive tzdata')
|
@@ -1,17 +1,17 @@
|
|
1
|
+
require_relative 'linux'
|
2
|
+
|
1
3
|
module VagrantPlugins
|
2
4
|
module TimeZone
|
3
5
|
module Cap
|
4
6
|
# Gentoo capabilities for changing time zone
|
5
|
-
class Gentoo
|
6
|
-
# Set the time zone
|
7
|
-
def self.
|
7
|
+
class Gentoo < Linux
|
8
|
+
# Set the time zone if `timedatectl` is not found
|
9
|
+
def self.change_timezone_generic(machine, timezone)
|
8
10
|
machine.communicate.tap do |comm|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
comm.sudo('emerge --config timezone-data')
|
14
|
-
end
|
11
|
+
super
|
12
|
+
|
13
|
+
comm.sudo("echo '#{timezone}' > /etc/timezone")
|
14
|
+
comm.sudo('emerge --config timezone-data')
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'unix'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module TimeZone
|
5
|
+
module Cap
|
6
|
+
# Generic Linix capability for changing time zone
|
7
|
+
class Linux
|
8
|
+
# Set the time zone.
|
9
|
+
# Uses `timedatectl` if found.
|
10
|
+
def self.change_timezone(machine, timezone)
|
11
|
+
if timedatectl?(machine)
|
12
|
+
change_timezone_timedatectl(machine, timezone)
|
13
|
+
else
|
14
|
+
change_timezone_generic(machine, timezone)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.timedatectl?(machine)
|
19
|
+
machine.communicate.test('which timedatectl', sudo: true)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.change_timezone_timedatectl(machine, timezone)
|
23
|
+
machine.communicate.sudo("timedatectl set-timezone '#{timezone}'")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set the time zone if `timedatectl` is not found.
|
27
|
+
# Defaults to `Unix.change_timezone`, but is overridden by distro
|
28
|
+
# specific classes.
|
29
|
+
def self.change_timezone_generic(machine, timezone)
|
30
|
+
Unix.change_timezone(machine, timezone)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,16 +1,17 @@
|
|
1
|
-
require_relative '
|
1
|
+
require_relative 'linux'
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module TimeZone
|
5
5
|
module Cap
|
6
6
|
# RedHat capabilities for changing time zone
|
7
|
-
class RedHat <
|
8
|
-
# Set the time zone
|
9
|
-
def self.
|
7
|
+
class RedHat < Linux
|
8
|
+
# Set the time zone if `timedatectl` is not found
|
9
|
+
def self.change_timezone_generic(machine, timezone)
|
10
10
|
super
|
11
11
|
|
12
12
|
machine.communicate.sudo(
|
13
|
-
"echo 'ZONE=\"#{timezone}\"' > /etc/sysconfig/clock"
|
13
|
+
"echo 'ZONE=\"#{timezone}\"' > /etc/sysconfig/clock"
|
14
|
+
)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -26,7 +26,7 @@ module VagrantPlugins
|
|
26
26
|
|
27
27
|
# We set timezone offset negative to match POSIX standards
|
28
28
|
# https://github.com/eggert/tz/blob/master/etcetera
|
29
|
-
@value =
|
29
|
+
@value = format('Etc/GMT%+d', -(Time.now.utc_offset / 3600))
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -8,7 +8,7 @@ module VagrantPlugins
|
|
8
8
|
# @!parse class Plugin < Vagrant::Plugin::V2::Plugin; end
|
9
9
|
class Plugin < Vagrant.plugin('2')
|
10
10
|
# Compatible Vagrant versions
|
11
|
-
VAGRANT_VERSION_REQUIREMENT = '>= 1.2.0'
|
11
|
+
VAGRANT_VERSION_REQUIREMENT = '>= 1.2.0'.freeze
|
12
12
|
|
13
13
|
# Returns true if the Vagrant version fulfills the requirements
|
14
14
|
#
|
@@ -16,7 +16,8 @@ module VagrantPlugins
|
|
16
16
|
# @return [Boolean]
|
17
17
|
def self.check_vagrant_version(*requirements)
|
18
18
|
Gem::Requirement.new(*requirements).satisfied_by?(
|
19
|
-
Gem::Version.new(Vagrant::VERSION)
|
19
|
+
Gem::Version.new(Vagrant::VERSION)
|
20
|
+
)
|
20
21
|
end
|
21
22
|
|
22
23
|
# Verifies that the Vagrant version fulfills the requirements
|
@@ -24,18 +25,19 @@ module VagrantPlugins
|
|
24
25
|
# @raise [VagrantPlugins::TimeZone::VagrantVersionError] if this plugin
|
25
26
|
# is incompatible with the Vagrant version
|
26
27
|
def self.check_vagrant_version!
|
27
|
-
if
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
return if check_vagrant_version(VAGRANT_VERSION_REQUIREMENT)
|
29
|
+
|
30
|
+
msg = I18n.t(
|
31
|
+
'vagrant_timezone.errors.vagrant_version',
|
32
|
+
requirement: VAGRANT_VERSION_REQUIREMENT.inspect
|
33
|
+
)
|
34
|
+
warn msg
|
35
|
+
raise msg
|
34
36
|
end
|
35
37
|
|
36
38
|
# Initializes the internationalization strings
|
37
39
|
def self.setup_i18n
|
38
|
-
I18n.load_path << File.expand_path('
|
40
|
+
I18n.load_path << File.expand_path('../../locales/en.yml', __dir__)
|
39
41
|
I18n.reload!
|
40
42
|
end
|
41
43
|
|
@@ -59,17 +61,7 @@ module VagrantPlugins
|
|
59
61
|
hook.after Vagrant::Action::Builtin::Provision, Action::SetTimeZone
|
60
62
|
end
|
61
63
|
|
62
|
-
guest_capability '
|
63
|
-
require_relative 'cap/arch'
|
64
|
-
Cap::Arch
|
65
|
-
end
|
66
|
-
|
67
|
-
guest_capability 'coreos', 'change_timezone' do
|
68
|
-
require_relative 'cap/coreos'
|
69
|
-
Cap::CoreOS
|
70
|
-
end
|
71
|
-
|
72
|
-
guest_capability 'darwin', 'change_timezone' do
|
64
|
+
guest_capability 'bsd', 'change_timezone' do
|
73
65
|
require_relative 'cap/unix'
|
74
66
|
Cap::Unix
|
75
67
|
end
|
@@ -79,24 +71,14 @@ module VagrantPlugins
|
|
79
71
|
Cap::Debian
|
80
72
|
end
|
81
73
|
|
82
|
-
guest_capability 'freebsd', 'change_timezone' do
|
83
|
-
require_relative 'cap/unix'
|
84
|
-
Cap::Unix
|
85
|
-
end
|
86
|
-
|
87
74
|
guest_capability 'gentoo', 'change_timezone' do
|
88
75
|
require_relative 'cap/gentoo'
|
89
76
|
Cap::Gentoo
|
90
77
|
end
|
91
78
|
|
92
|
-
guest_capability '
|
93
|
-
require_relative 'cap/
|
94
|
-
Cap::
|
95
|
-
end
|
96
|
-
|
97
|
-
guest_capability 'openbsd', 'change_timezone' do
|
98
|
-
require_relative 'cap/unix'
|
99
|
-
Cap::Unix
|
79
|
+
guest_capability 'linux', 'change_timezone' do
|
80
|
+
require_relative 'cap/linux'
|
81
|
+
Cap::Linux
|
100
82
|
end
|
101
83
|
|
102
84
|
guest_capability 'redhat', 'change_timezone' do
|
data/locales/en.yml
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../test/acceptance/support/box_helper'
|
4
|
+
|
5
|
+
desc 'Run all acceptance tests'
|
6
|
+
task acceptance: 'acceptance:all'
|
7
|
+
|
8
|
+
namespace :acceptance do
|
9
|
+
include VagrantTimezone::BoxHelper
|
10
|
+
|
11
|
+
task all: providers
|
12
|
+
|
13
|
+
providers.each do |provider|
|
14
|
+
desc "Run all acceptance tests for #{provider}"
|
15
|
+
task provider => provider.boxes.map { |box| "#{provider}:#{box}" }
|
16
|
+
|
17
|
+
namespace provider.name do
|
18
|
+
provider.boxes.each do |box|
|
19
|
+
desc "Run acceptance tests for #{box} on #{provider}"
|
20
|
+
task box.name => box.path do
|
21
|
+
env = {
|
22
|
+
'VAGRANT_SPEC_PROVIDER' => provider.name,
|
23
|
+
'VAGRANT_SPEC_BOX_PATH' => box.path.to_s
|
24
|
+
}
|
25
|
+
cmd = ['bundle', 'exec', 'vagrant-spec', 'test']
|
26
|
+
cmd << "--config=#{config_path('vagrant-spec.config.rb')}"
|
27
|
+
|
28
|
+
rake_output_message "Running acceptance tests for #{box} on #{provider}"
|
29
|
+
rake_output_message cmd.join(' ')
|
30
|
+
system(env, *cmd)
|
31
|
+
end
|
32
|
+
|
33
|
+
file box.path => provider.box_dir do
|
34
|
+
rake_output_message "Downloading #{box} for #{provider}"
|
35
|
+
download(box)
|
36
|
+
end
|
37
|
+
|
38
|
+
directory provider.box_dir
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../support/spec_helper.rb'
|
4
|
+
|
5
|
+
Vagrant::Spec::Acceptance.configure do |c|
|
6
|
+
provider = ENV.fetch('VAGRANT_SPEC_PROVIDER')
|
7
|
+
box_path = ENV.fetch('VAGRANT_SPEC_BOX_PATH')
|
8
|
+
|
9
|
+
c.component_paths = [File.expand_path('../vagrant-timezone', __dir__)]
|
10
|
+
c.skeleton_paths = [File.expand_path('../skeletons', __dir__)]
|
11
|
+
|
12
|
+
c.provider(provider, box_path: box_path)
|
13
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'json'
|
6
|
+
require 'open-uri'
|
7
|
+
require 'pathname'
|
8
|
+
require 'tempfile'
|
9
|
+
require 'yaml'
|
10
|
+
|
11
|
+
module VagrantTimezone
|
12
|
+
module BoxHelper
|
13
|
+
ROOT_DIR = Pathname.new(__dir__).join('..')
|
14
|
+
BOX_DIR = ROOT_DIR.join('boxes')
|
15
|
+
CONFIG_DIR = ROOT_DIR.join('config')
|
16
|
+
|
17
|
+
def config_path(file_name)
|
18
|
+
CONFIG_DIR.join(file_name)
|
19
|
+
end
|
20
|
+
|
21
|
+
def providers
|
22
|
+
@providers ||= begin
|
23
|
+
data = IO.read(config_path('boxes.yaml'))
|
24
|
+
YAML.safe_load(data).map do |provider, boxes|
|
25
|
+
Provider.new(provider, boxes)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def download(box)
|
31
|
+
Downloader.download(box)
|
32
|
+
end
|
33
|
+
|
34
|
+
class Provider
|
35
|
+
attr_reader :name, :boxes
|
36
|
+
|
37
|
+
def initialize(name, box_names)
|
38
|
+
@name = name
|
39
|
+
@boxes = box_names.map { |box| Box.new(box, self) }
|
40
|
+
end
|
41
|
+
|
42
|
+
alias to_s name
|
43
|
+
|
44
|
+
def box_dir
|
45
|
+
@box_dir ||= BOX_DIR.join(name)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Box
|
50
|
+
attr_reader :name, :provider
|
51
|
+
|
52
|
+
def initialize(name, provider)
|
53
|
+
%r{^[^/]+/[^/]+$}.match(name) ||
|
54
|
+
raise(ArgumentError, 'Box names must be in form of <user>/<box>')
|
55
|
+
|
56
|
+
@name = name
|
57
|
+
@provider = provider
|
58
|
+
end
|
59
|
+
|
60
|
+
alias to_s name
|
61
|
+
|
62
|
+
def path
|
63
|
+
@path ||= provider.box_dir.join("#{sanitized_name}.box")
|
64
|
+
end
|
65
|
+
|
66
|
+
def sanitized_name
|
67
|
+
name.tr('/', '_')
|
68
|
+
end
|
69
|
+
|
70
|
+
def metadata_url
|
71
|
+
user, box = name.split('/')
|
72
|
+
URI("https://app.vagrantup.com/#{CGI.escape(user)}/boxes/#{box}.json")
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Downloader
|
77
|
+
def self.download(box)
|
78
|
+
metadata = download_metadata(box)
|
79
|
+
|
80
|
+
url = find_url(metadata, box.provider)
|
81
|
+
raise StandardError, "No active versions found for #{box} for #{box.provider}" if !url
|
82
|
+
|
83
|
+
download_box(box, url)
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.download_metadata(box)
|
87
|
+
data = box.metadata_url.open.read
|
88
|
+
JSON.parse(data)
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.download_box(box, url)
|
92
|
+
case io = url.open
|
93
|
+
when Tempfile
|
94
|
+
io.close
|
95
|
+
FileUtils.mv(io.path, box.path)
|
96
|
+
else
|
97
|
+
IO.copy_stream(io, box.path)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.find_url(metadata, provider)
|
102
|
+
metadata['versions'].each do |v|
|
103
|
+
next if v['status'] != 'active'
|
104
|
+
|
105
|
+
v['providers'].each do |p|
|
106
|
+
return URI(p['url']) if p['name'] == provider.name
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'vagrant-spec/acceptance'
|
4
|
+
|
5
|
+
# Dirty monkey patch to work around
|
6
|
+
# https://github.com/hashicorp/vagrant-spec/pull/17
|
7
|
+
module Vagrant
|
8
|
+
module Spec
|
9
|
+
class AcceptanceIsolatedEnvironment
|
10
|
+
attr_reader :env if !method_defined?(:env)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# Disable Vagrant's version checks
|
16
|
+
ENV['VAGRANT_CHECKPOINT_DISABLE'] = '1'
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
shared_examples 'provider/timezone' do |provider, options|
|
4
|
+
if !options[:box_path]
|
5
|
+
raise ArgumentError,
|
6
|
+
"'box_path' option must be specified for provider: #{provider}"
|
7
|
+
end
|
8
|
+
|
9
|
+
include_context 'acceptance'
|
10
|
+
|
11
|
+
if provider.to_s == 'virtualbox'
|
12
|
+
let(:extra_env) do
|
13
|
+
# Special magic for VirtualBox
|
14
|
+
{ 'VBOX_USER_HOME' => '{{homedir}}' }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
before do
|
19
|
+
environment.skeleton('timezone')
|
20
|
+
environment.env['VAGRANT_SPEC_TIMEZONE'] = timezone
|
21
|
+
|
22
|
+
assert_execute('vagrant', 'box', 'add', 'box', options[:box_path])
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
execute('vagrant', 'destroy', '--force')
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'when starting' do
|
30
|
+
context 'without configuration' do
|
31
|
+
let(:timezone) { nil }
|
32
|
+
|
33
|
+
it 'does not configure the time zone' do
|
34
|
+
result = assert_execute('vagrant', 'up', "--provider=#{provider}")
|
35
|
+
expect(result.stdout).not_to match(/Setting time zone/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'with a time zone name' do
|
40
|
+
# Something without DST so that the offset is always known
|
41
|
+
let(:timezone) { 'America/Argentina/Buenos_Aires' }
|
42
|
+
|
43
|
+
it 'configures the specified time zone' do
|
44
|
+
result = assert_execute('vagrant', 'up', "--provider=#{provider}")
|
45
|
+
expect(result.stdout).to match(/Setting time zone to '#{timezone}'/)
|
46
|
+
|
47
|
+
result = assert_execute('vagrant', 'ssh', '-c', 'date "+TZ: %z"')
|
48
|
+
expect(result.stdout).to match(/^TZ: -0300$/)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'when reloading' do
|
54
|
+
context 'with :host' do
|
55
|
+
# First configure to something else than the host
|
56
|
+
let(:timezone) do
|
57
|
+
offset = host_offset[0, 3].to_i
|
58
|
+
offset = 10 if offset.zero?
|
59
|
+
# Negate the host offset!
|
60
|
+
# https://github.com/eggert/tz/blob/master/etcetera
|
61
|
+
Kernel.format('Etc/GMT%+d', offset)
|
62
|
+
end
|
63
|
+
|
64
|
+
let(:host_offset) { `date "+%z"`.chomp }
|
65
|
+
|
66
|
+
it 'configures the same time zone than on the host' do
|
67
|
+
status('First start the machine with other timezone')
|
68
|
+
assert_execute('vagrant', 'up', "--provider=#{provider}")
|
69
|
+
|
70
|
+
# Change the configuration in Vagrantfile
|
71
|
+
environment.env['VAGRANT_SPEC_TIMEZONE'] = ':host'
|
72
|
+
|
73
|
+
status('Reloading with :host')
|
74
|
+
result = assert_execute('vagrant', 'reload')
|
75
|
+
expect(result.stdout).to match(%r{Setting time zone to 'Etc/GMT})
|
76
|
+
|
77
|
+
result = assert_execute('vagrant', 'ssh', '-c', 'date "+TZ: %z"')
|
78
|
+
expect(result.stdout).to match(/^TZ: #{Regexp.escape(host_offset)}$/)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/test/spec_helper.rb
ADDED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'vagrant-timezone/config'
|
3
4
|
|
4
5
|
describe VagrantPlugins::TimeZone::Config do
|
@@ -23,7 +24,7 @@ describe VagrantPlugins::TimeZone::Config do
|
|
23
24
|
end
|
24
25
|
|
25
26
|
it 'converts `:host` to the zone of the host' do
|
26
|
-
allow(Time).to receive(:now).and_return(Time.new(2016,7,10,2,12,0, '+03:00'))
|
27
|
+
allow(Time).to receive(:now).and_return(Time.new(2016, 7, 10, 2, 12, 0, '+03:00'))
|
27
28
|
subject.value = :host
|
28
29
|
subject.finalize!
|
29
30
|
expect(subject.value).to eq('Etc/GMT-3')
|
data/vagrant-timezone.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'vagrant-timezone/version'
|
5
4
|
|
@@ -22,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
22
21
|
'Blue.Dog.Archolite@gmail.com'
|
23
22
|
]
|
24
23
|
|
25
|
-
spec.files = `git ls-files`.split(
|
24
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
26
25
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
27
26
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
28
27
|
spec.require_paths = ['lib']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-timezone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Teemu Matilainen
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2019-01-10 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: A Vagrant plugin that configures the time zone of a virtual machine
|
16
16
|
email:
|
@@ -22,18 +22,20 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
files:
|
24
24
|
- ".gitignore"
|
25
|
+
- ".rspec"
|
26
|
+
- ".rubocop.yml"
|
25
27
|
- ".travis.yml"
|
26
28
|
- CHANGELOG.md
|
27
29
|
- Gemfile
|
30
|
+
- Guardfile
|
28
31
|
- LICENSE.txt
|
29
32
|
- README.md
|
30
33
|
- Rakefile
|
31
34
|
- lib/vagrant-timezone.rb
|
32
35
|
- lib/vagrant-timezone/action/set_timezone.rb
|
33
|
-
- lib/vagrant-timezone/cap/arch.rb
|
34
|
-
- lib/vagrant-timezone/cap/coreos.rb
|
35
36
|
- lib/vagrant-timezone/cap/debian.rb
|
36
37
|
- lib/vagrant-timezone/cap/gentoo.rb
|
38
|
+
- lib/vagrant-timezone/cap/linux.rb
|
37
39
|
- lib/vagrant-timezone/cap/redhat.rb
|
38
40
|
- lib/vagrant-timezone/cap/unix.rb
|
39
41
|
- lib/vagrant-timezone/cap/windows.rb
|
@@ -42,9 +44,16 @@ files:
|
|
42
44
|
- lib/vagrant-timezone/plugin.rb
|
43
45
|
- lib/vagrant-timezone/version.rb
|
44
46
|
- locales/en.yml
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
47
|
+
- tasks/acceptance.rake
|
48
|
+
- test/acceptance/config/boxes.yaml
|
49
|
+
- test/acceptance/config/vagrant-spec.config.rb
|
50
|
+
- test/acceptance/skeletons/timezone/Vagrantfile
|
51
|
+
- test/acceptance/support/box_helper.rb
|
52
|
+
- test/acceptance/support/spec_helper.rb
|
53
|
+
- test/acceptance/vagrant-timezone/timezone_spec.rb
|
54
|
+
- test/spec_helper.rb
|
55
|
+
- test/unit/vagrant-timezone/cap/windows_spec.rb
|
56
|
+
- test/unit/vagrant-timezone/config_spec.rb
|
48
57
|
- vagrant-timezone.gemspec
|
49
58
|
homepage: http://github.com/tmatilai/vagrant-timezone
|
50
59
|
licenses:
|
@@ -65,12 +74,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
74
|
- !ruby/object:Gem::Version
|
66
75
|
version: '0'
|
67
76
|
requirements: []
|
68
|
-
|
69
|
-
rubygems_version: 2.6.10
|
77
|
+
rubygems_version: 3.0.1
|
70
78
|
signing_key:
|
71
79
|
specification_version: 4
|
72
80
|
summary: A Vagrant plugin that configures the time zone of a virtual machine
|
73
81
|
test_files:
|
74
|
-
-
|
75
|
-
-
|
76
|
-
-
|
82
|
+
- test/acceptance/config/boxes.yaml
|
83
|
+
- test/acceptance/config/vagrant-spec.config.rb
|
84
|
+
- test/acceptance/skeletons/timezone/Vagrantfile
|
85
|
+
- test/acceptance/support/box_helper.rb
|
86
|
+
- test/acceptance/support/spec_helper.rb
|
87
|
+
- test/acceptance/vagrant-timezone/timezone_spec.rb
|
88
|
+
- test/spec_helper.rb
|
89
|
+
- test/unit/vagrant-timezone/cap/windows_spec.rb
|
90
|
+
- test/unit/vagrant-timezone/config_spec.rb
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module TimeZone
|
3
|
-
module Cap
|
4
|
-
# Arch capabilities for changing time zone
|
5
|
-
class Arch
|
6
|
-
# Set the time zone
|
7
|
-
def self.change_timezone(machine, timezone)
|
8
|
-
machine.communicate.sudo("timedatectl set-timezone '#{timezone}'")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module TimeZone
|
3
|
-
module Cap
|
4
|
-
# CoreOS capabilities for changing time zone
|
5
|
-
class CoreOS
|
6
|
-
# Set the time zone
|
7
|
-
def self.change_timezone(machine, timezone)
|
8
|
-
machine.communicate.sudo("timedatectl set-timezone '#{timezone}'")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|