fosdem - does your configuration code smell?

48
Does Your Configuration Code Smell? Tushar Sharma

Upload: tushar-sharma

Post on 08-Feb-2017

214 views

Category:

Software


0 download

TRANSCRIPT

  • Does Your Configuration Code Smell?

    TusharSharma

  • Smells

    Code Smell

    certain structures in the

    code that suggest (sometimes

    they scream for) the

    possibility of refactoring.

    2

  • 3

  • Jugaad

    Jugaad is a colloquial Hindi word that can mean an

    innovative fix or a simple work-around, used for solutions

    that bend rules, or a resource that can be used as such, or

    a person who can solve a complicated issue.

    a work-around or hack

    4

  • Jugaad

    5

  • Jugaad

    6

  • Jugaad

    7

  • Jugaad

    8

  • Jugaad

    9

  • Smells are Jugaads in software

    10

  • 11

  • Smells

    Design Smells

    Design smells are certain

    structures in the design that

    indicate violation of fundamental

    design principles and negatively

    impact design quality.

    12

  • Configuration Smells

    13

  • Infrastructure as Code (IaC)

    14

  • Puppet example

    package { 'apache2':

    require => Exec['apt-update'],

    ensure => installed,

    }

    service { 'apache2':

    ensure => running,

    require => Package[apache2]

    }

    user { 'tushar':

    ensure => present,

    uid => '1000',

    gid => '1000',

    shell => '/bin/bash',

    home => '/home/tushar'

    }

    Configuration management tools:

    Ansible, Chef, CFEngine, Puppet 15

  • Software System

    IaC and Traditional SE

    Production code

    Infrastructure, configuration

    code, tools and services

    Apply traditional software

    engineering practices

    16

  • Configuration smells

    Configuration smells are the characteristics of a

    configuration program or script that violate the

    recommended best practices and potentially

    affect the programs quality in a negative way.

    17

  • Implementation configuration smells

    18

  • Implementation configuration smellsimport'classes/*'#TODO:fixdeprecatedstatementclassapp-studio(String$version=latest'){$primary_config_file='config'$source_config='config.source'if$version==44or$version==4.2or$version!=4.5or$version==4.9{case$::operatingsystem{'debian':{apt::source{'packages.dotdeb.org-repo.app':location=>'http://repo.app.com/dotdeb/',release=>$::lsbdistcodename,repos=>'all',include_src=>trueinclude_src=>true}}}

    DeprecatedStatementUsage

    IncompleteTask

    DuplicateEntity

    LongStatement

    ComplexExpressionMissingDefaultCase

    19

  • Implementation configuration smellselsif$versionin['33','3.3']{}if$::kernelversion=~/^(2.2)/{$appversion='3.5'}elsif$::kernelversion=~/^(2.1)/{exec{"download_app_studio":command=>"wget$url",

    timeout=>0,}}$version='3.4'?{undef=>$primary_config_file,default=>$source_config}

    file{"/root/.app":mode=>'644',ensure=>present

    }}

    MissingConditional

    ImproperQuoteUsageUnguardedVariable

    ImproperAlignment

    InvalidPropertyValueMisplacedAttribute

    20

  • Design configuration smells

    21

  • package.pp

    22

  • apache.pp

    23

  • Multifaceted Abstraction

    Eachabstractionshouldbedesignedtospecifythepropertiesofasinglepieceofsoftware.

    24

  • init.pp

    25

  • Unnecessary Abstraction

    Aclass,define,ormodulemustcontaindeclarationsorstatementsspecifyingthepropertiesofadesiredsystem.

    26

  • init.pp

    27

  • Imperative Abstraction

    Anabstractioncontainingnumerousimperativestatementssuffersfromimperativeabstractionsmell.

    28

  • init.pp

    29

  • Missing Abstraction

    Amodulesuffersfromthemissingabstractionsmellwhenresourcesandlanguageelementsaredeclaredandusedwithout

    encapsulatingtheminanabstraction.

    30

  • web.pp server.pp

    31

  • Duplicate Block

    Aduplicateblockofstatementsmorethanathresholdindicatesthatprobablyasuitableabstractiondefinitionismissing.

    32

  • init.pp

    33

  • Insufficient Modularisation

    Anabstractionsuffersfromthissmellwhenitislargeorcomplexandthuscanbemodularizedfurther.

    34

  • 35

  • Unstructured ModuleEachmoduleinaconfigurationrepositorymusthaveawell-

    definedandconsistentmodulestructure.

    RepoName

    ManifestsModulesREADME

    ApacheAdobe

    fileslibmanifestsspectemplatestestsREADME

    36

  • 37

  • Dense StructureThissmellariseswhenaconfigurationcoderepositoryhas

    excessiveanddensedependencies.

    38

  • 39

  • Weekend ModularityThissmellariseswhenamoduleexhibitshighcouplingand

    lowcohesion.

    Modularityratio(A)=Cohesion(A)

    Coupling(A)

    40

  • Implications of smells

    Thestrawthatbrokethecamel'sback41

  • Detecting configuration smells

    Implementation configuration smells

    Puppet-lint [1]

    Additional custom rules in Puppeteer

    Design configuration smells

    Puppeteer [2] an open source tool

    1. http://puppet-lint.com/

    2. https://github.com/tushartushar/Puppeteer42

  • Mining GitHub RepositoriesRepositories 4,621

    Puppet files 142,662

    Class declarations 132,323

    Define declarations 39,263

    File resources 117,286

    Package resources 49,841

    Service resources 18,737

    Exec declarations 43,468

    Lines of code (Puppet only) 8,948,611

    http://www.tusharma.in/research/does-your-configuration-code-smell-msr-2016/ 43

  • Let us summarize

    ME

    LS

    U

    P

    EER

    II

    P

    T

    U

    I NM YI

    IA A BNC

    44

  • Let us summarize

    ME

    LS

    U

    P

    EER

    II

    P

    T

    U

    IA NM YI

    IA A BNC

    45

  • Let us summarize

    SME

    LS

    U

    P

    EER

    L II

    P

    T

    U

    IA NM YI

    IA A BNC

    46

  • Let us summarize

    SME

    LS

    U

    P

    P

    EER

    L II

    P

    T

    U

    IA NM YI

    IT A A BNC

    47

  • Thank you!!

    Courtesy:spikedmath.com

    Tushar [email protected]

    @Sharma__Tushar

    48