presentation: testing & code sample
This commit is contained in:
parent
1307bc4804
commit
d679c3fc71
@ -201,25 +201,24 @@ Note:
|
|||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# attributes/default.rb
|
# attributes/default.rb
|
||||||
default.ntp.subnets = ["::1", "127.0.0.1"]
|
|
||||||
default.ntp.server = "de.pool.ntp.org"
|
default.ntp.server = "de.pool.ntp.org"
|
||||||
|
default.ntp.subnets = ["::1", "127.0.0.1"]
|
||||||
```
|
```
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# recipies/default.rb
|
# recipies/default.rb
|
||||||
package 'ntp'
|
package 'ntp'
|
||||||
|
|
||||||
service "ntp" do
|
|
||||||
service_name "ntp"
|
|
||||||
action [:enable, :start]
|
|
||||||
end
|
|
||||||
|
|
||||||
template "/etc/ntp.conf" do
|
template "/etc/ntp.conf" do
|
||||||
owner "root"
|
owner "root"
|
||||||
group "root"
|
group "root"
|
||||||
source "ntp.conf.erb"
|
source "ntp.conf.erb"
|
||||||
notifies :restart, "service[ntp]"
|
notifies :restart, "service[ntp]"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
service "ntp" do
|
||||||
|
action [:enable, :start]
|
||||||
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
@ -235,7 +234,45 @@ restrict default noquery nopeer
|
|||||||
driftfile /var/lib/ntp/ntp.drift
|
driftfile /var/lib/ntp/ntp.drift
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note:
|
||||||
|
- das beliebte Hello-World für Provisionierungssysteme: Einrichten eines
|
||||||
|
NTP-Servers
|
||||||
|
- Hier ein Beispiel, welches ich für die Abschlussaufgabe geschrieben habe
|
||||||
|
- attribute: In der Attribute-Datei - Standwerte für ntp: upstream server,
|
||||||
|
subnets auf dem ntp lauscht
|
||||||
|
- recipe:
|
||||||
|
- package: Packet per apt installieren
|
||||||
|
- template: Konfiguration aus template generieren - hier Abhängigkeiten
|
||||||
|
zwischen Resourcen, wenn Template sich ändert -> NTP neustarten
|
||||||
|
- zum Schluss den Dienst aktivieren und starten
|
||||||
|
- template:
|
||||||
|
- Beispiel für ERB-Template
|
||||||
|
- Tags -> Ruby-Code, wird interpoliert
|
||||||
|
- Verzweigungen und Schleifen möglich
|
||||||
|
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
|
```
|
||||||
|
require_relative '../spec_helper'
|
||||||
|
|
||||||
|
describe 'ntp::default' do
|
||||||
|
let(:chef_run) do
|
||||||
|
ChefSpec::Runner.new do |node|
|
||||||
|
node.set["ntp"]["subnets"] = ["::1", "127.0.0.1", "172.28.128.0 mask 255.255.255.0 nomodify notrap nopeer"]
|
||||||
|
end.converge(described_recipe)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should setup ntp" do
|
||||||
|
chef_run.should install_package("ntp")
|
||||||
|
chef_run.should render_file("/etc/ntp.conf").with_content("172.28.128.0")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Note:
|
||||||
|
- Infrastruktur: schwierig zu testen, viele externe Abhängigkeiten, langsam
|
||||||
|
- Ruby: dynamische Programmiersprache -> Tippfehler, keine Compilerwarnung beim
|
||||||
|
Refactoring
|
||||||
|
|
||||||
## Demo
|
## Demo
|
||||||
|
@ -6,4 +6,9 @@ template "/etc/ntp.conf" do
|
|||||||
owner "root"
|
owner "root"
|
||||||
group "root"
|
group "root"
|
||||||
source "ntp.conf.erb"
|
source "ntp.conf.erb"
|
||||||
|
notifies :restart, "service[ntp]"
|
||||||
|
end
|
||||||
|
|
||||||
|
service "ntp" do
|
||||||
|
action [:enable, :start]
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user